Escaping xml tags inside xml

I have a python script that parses an XML file and executes commands. I want my xml read another XML file and edit it. For this, I used the perl command

 "perl -pi -0777 -e ' s@ <en:TagName>.*?</en:TagName>@<en:TagName>new-value</en:TagName>@sg'FileName.xml" 

I added this to my XML file, which is analyzed by the shell script.

 <cmd>perl -pi -0777 -e ' s@ <en:TagName>.*?</en:TagName>@<en:TagName>new-value</en:TagName>@sg'FileName.xml</cmd> 

here my python script processes <en:TagName> as a tag and cannot <en:TagName> it. So I added "perl -pi -0777 -e 's#&lt;en:TagName&gt;.*?&lt;en:TagName&gt;#&lt;en:tagName&gt;new-value&lt;/en:TagName&gt;#sg' FileName.xml" , and also used" # "as a separator (since @ is a special character in the shell script that we use)

Room # cannot provide the desired result. Instead of replacing it is adding a new value to the end.

+4
source share
1 answer

Surround your commands perl CDATA tags:

 Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA. Everything inside a CDATA section is ignored by the parser. A CDATA section starts with "<![CDATA[" and ends with "]]>" 
+4
source

All Articles