I am traversing an xml document using w3c DOM and I need to wrap the substring of the text content inside an org.w3c.dom.Element
with some tag based on some business logic.
For example, I want to turn
<title id="1">Java is a cool programming language</title>
into
<title id="1">Java is a <blah id="2">cool</blah> programming language</title>
I don't insist on using the w3c DOM library for my application so 开发者_StackOverflow社区any suggestions are welcome in terms of other libraries that could accomplish this.
All text in an XML document will be parsed by the parser.
But text inside a CDATA section will be ignored by the parser.
try this
<title id="1">Java is a <![CDATA[<blah id="2">cool</blah> ]]>programming language</title>
Typically you'd use <
and >
(and others) to construct such tags in your node values. These are so called 'entity references. See for example here for some info about them; Google/Bing/YourFavouriteSearchEngine for more details.
In your example, this would mean you'd use:
<title id="1">Java is a <blah id="2">cool</blah> programming language</title>
Cheers, Wim
精彩评论