Gilbeg
Gilbeg

Reputation: 761

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 somebody shed some lights here....

thanks!

Upvotes: 0

Views: 357

Answers (1)

MeBigFatGuy
MeBigFatGuy

Reputation: 28598

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.

Upvotes: 0

Related Questions