Vir
Vir

Reputation: 1354

problem while encoding string to XML

i am gettting problem while encoding string R.F.< 1 into Xml

i am using node.innerxml=string;

it shows exeption name cannot start with 1 or hexadecimal value 0x33.....

pls help me to solve this

Upvotes: 1

Views: 419

Answers (2)

Jeffrey L Whitledge
Jeffrey L Whitledge

Reputation: 59443

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.&lt; 1) in the resulting XML document.

Upvotes: 1

DaveRead
DaveRead

Reputation: 3413

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

Upvotes: 0

Related Questions