简体   繁体   English

使用SAX解析XHTML仅更改PCDATA

[英]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. 我正在寻找一个使用Sax解析器解析XHTML字符串并将字符串(s1)的每次出现更改为(s2)的示例(如果s1在PCDATA中而不是属性中)。 Can somebody 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. ContentHandler的方法,然后查找s1并替换为s2。

Of course, this assumes that your content handler is outputing an xml to some stream. 当然,这假设您的内容处理程序正在将xml输出到某个流。

From your description, really you probably want to use an XMLFilter to modify the xml stream in place. 根据您的描述,您实际上可能真的想使用XMLFilter来修改xml流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM