Java를 사용하여 XML 문서의 텍스트를 바꾸려면 어떻게해야합니까?Java를 사용하여 XML 문서의 텍스트를 바꾸는 방법
출처 :
<body>
<title>Home Owners Agreement</title>
<p>The <b>good</b> thing about a Home Owners Agreement is that...</p>
</body>
원하는 출력 :
<body>
<title>Home Owners Agreement</title>
<p>The <b>good</b> thing about a HOA is that...</p>
</body>
난 단지 <p>
태그 텍스트를 교체해야합니다.
replaceText(string term, string replaceWith, org.w3c.dom.Node p){
p.setTextContent(p.getTextContent().replace(term, replaceWith));
}
위의 코드의 문제는 p
의 모든 자식 노드가 길을 잃지이다 : 나는 다음 시도했다.
고마워. 정규 표현식은 가능하지만, 실제로해야 할 일에서 단순화됩니다. 내가 대체하는 것은 다양한 중첩 요소에 따라 달라집니다. System.Xml.XmlNode.InnerXml을 대체하여 C#을 사용하여 대체물을 쉽게 구현할 수있었습니다. – joe