Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encode & symbol in XML

Tags:

xml

perl

My Perl program is processing an XML file. Some entries may contain & symbols. And the parser breaks, saying: "Invalid name in entity".

How can I process the file and encode &-s in all the incorrect entities?

So, it will be something like this:

<words>text1 & text2</words>  -->  <words>text1 &amp; text2</words>
like image 235
user4035 Avatar asked Mar 10 '26 20:03

user4035


1 Answers

It's not an XML file. If it were XML, the & would be written as &amp;. Processing non-XML files is difficult because you can't use an XML parser. It's best to fix the program that created this file, changing it to produce proper well-formed XML.

like image 161
Michael Kay Avatar answered Mar 13 '26 10:03

Michael Kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!