开发者

Parsing XHTML using SAX to change only the PCDATA

I am looking for an example of using Sax parser to parse an XHTML string and change every single occurence of a string (s1) to (s2) if s1 is in the PCDATA not attributes. Can someb开发者_如何学编程ody shed some lights here....

thanks!


You would just implement the

characters(char[] ch, int start, int length) 

method of ContentHandler and look for s1 and replace with s2.

Of course, this assumes that your content handler is outputing an xml to some stream.

From your description, really you probably want to use an XMLFilter to modify the xml stream in place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜