简体   繁体   中英

How to escape Special character in XML

I have XML data in string and tried to convert that string in to XML using

XmlDocument xl=new XmlDocument();
xl.LoadXml(mystring);

It was not parsing because my string has special character in XML element like below.

<ROOT>
 <SUB>
   <DATA>name < lastname</DATA>
   <DATA>Myname > lastname</DATA>
   <DATA>some special character in between text</DATA>
    ......
    .....
 </ROOT>
</SUB>

There were many <DATA> in my XML. It was generating dynamically.

I have tried to change < &lt; > &gt; < &lt; > &gt; but it was replacing other XML tags. How to escape above special characters without change other XML tags?

Use below strings in XML

   &lt; ==>  lesser-than = <
   &gt; ==> greater-than = >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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