problem while encoding string to XML
i am gettting problem while encoding string R.F.< 1 into X开发者_JAVA技巧ml
i am using node.innerxml=string;
it shows exeption name cannot start with 1 or hexadecimal value 0x33.....
pls help me to solve this
The InnerXml
property of an XmlNode
instance accepts only well-formed XML text. Whenever you attempt to apply the string R.F.< 1
, the less-than character is being interpreted as the beginning of an XML element tag. Since an element name cannot begin with a digit, the XML is deemed not to be well-formed, and the set operation fails.
If you wish to put arbitrary text inside an XmlNode, then you should use the InnerText
property rather than the InnerXml
property. This will ensure that the less-than character is properly escaped (R.F.< 1
) in the resulting XML document.
When encoding to XML you need to consider reserved XML characters, and encode them accordingly.
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
精彩评论