开发者

why XMLDocument AppendChild() adds "amp" to a xml node string value?

开发者 https://www.devze.com 2023-02-03 20:05 出处:网络
i have a URL string that i want to insert to an XMLDocument - XmlElement Node: \"http://xx.xxx.xxx.xx4:7000/SomeURL/Some/?Locale=asaf&;Portal=how\"

i have a URL string that i want to insert to an XMLDocument - XmlElement Node:

"http://xx.xxx.xxx.xx4:7000/SomeURL/Some/?Locale=asaf&;Portal=how"

when write this code :

XmlElement NodeElement = xmlDoc.CreateElement(nodeToCreate);
NodeElement.InnerText = propInfo.GetValue(requestData,null).ToString();
additionalParamsNode.AppendChild(NodeElement);

The Text in the 'NodeElement.InnerText' looks fine, but when i do the appendChild() an "&amp" is written inside the XMLElement additionalParamsNode. its like the XMLElement takes the InnerXML , not the InnerText of the NodeElement.

i dont want to write the string with "开发者_如何学编程amp" to the XML cause the link wont work.

how do i appendChild without changing "&" to "&amp"?


If I'm remembering correctly, &'s are one of the illegal characters in XML. That's why it is turned into &amp (the html equivalent of &).

You should be able to wrap the data in CDATA tags.

<![CDATA[http://xx.xxx.xxx.xx4:7000/SomeURL/Some/?Locale=asaf&;Portal=how]]>

You might have to parse out the CDATA tags when you are done though.

0

精彩评论

暂无评论...
验证码 换一张
取 消