You may have more of a dilemma than you realize here: You're saying (I think) that you have existing XML that's non-conforming because it hasn't already used entities for the 3 required characters in the data: <, >, and &. < and > are difficult because you (obviously) want to leave them in the tags. That would mean to get it right, you'd have to parse the XML. However most parsers will, I think, get confused by the unescaped < and > characters. i.e., most parsers expect conforming XML. At any rate, if you can't simply regenerate the XML and do the entity conversion, I think you have to start by trying to parse it. Something like XML::Parser would be where I'd start, but I just tried feeding it some XML without escaped < and > characters and it flagged those as errors. Maybe there are settings that let you get around that.
For entity conversion (to or from) I like HTML::Entities. XML::Writer is nice in other respects, but it's entity conversion could be better. It only does the three above, it always does them named, and it's not smart enough to realize when there are & characters introducing entities that are already in the data.
In reply to Re: Re: Re: Escaping XML Reserved characters
by steves
in thread Escaping XML Reserved characters
by skinnymofo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |