tags:

views:

99

answers:

5

Hi there,

when I try to insert signs like < oder > in an InnerText-part of a xml-tag then after accessing the xml by xmlDocument.InnerXml these signs are replaced by their html-code like &lt oder &gt, can someone explain this to me and perhaps give me a solution for this problem?

with kind regards

Sebastian

+4  A: 

Those symbols have to be escaped because angle brackets are used as document structures. To deal with the issue, just make sure you're decoding the text properly.

Scott Muc
+2  A: 

You could also try enclosing your text in the CDATA section.

Filip
A: 

ah for sure, how could I be so blind, thank you

Xelluloid
This isn't an answer. Should really be a comment on whichever answer prompted the response.
workmad3
sry next time I do so
Xelluloid
A: 

It depends what you want to appear in the inner text. If you are actually trying to insert a new element, you are better off adding a new node instead to the Nodes collection (type = element). If you actually want text that renders as < and > then this is already doing exactly what you need.

If you can explain the final result you are aiming for with this operation, we can tell you exactly what you need to do.

DarkwingDuck
+3  A: 

By definition (see the spec) in an XML file, < is used to open an element. Similarly, > is used to close an element.

To allow for these (and a few other characters) to appear in the XML file, they get encoded as entities.

You should find this is all transparently handled for you - if you put a < into the content of an element, it will be stored as &lt; and then translated back when you get the content back out again.

If this is getting in your way because you're trying to add extra elements into your output file, you should look at the various APIs for creating elements directly -- writing text is going to fail.

Bevan