Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XmlElement to string conversion

Is there some simple way to convert XmlElement to string ?

like image 265
Night Walker Avatar asked Aug 01 '11 12:08

Night Walker


3 Answers

This will get the content of the element if the content is text:

element.Value

This will get the content of the element as XML:

element.InnerXml

This will get the element and its content as XML

element.OuterXml
like image 180
Guffa Avatar answered Oct 20 '22 02:10

Guffa


You can look at the Value or InnerText properties of the element.

However, without further details of exactly what you are looking, I can't help more.

Update:

Seeing as you want the XML of all nodes, using InnerXml or OuterXml should do nicely.

like image 39
Oded Avatar answered Oct 20 '22 03:10

Oded


Let's say you have this XmlElement:

<node>
  Hello
  <effect color="pink">
    World
  </effect>
</node>

With Console.Write(xmlElement.Inner) you see the inside of your node:

Hello <effect color="pink">World</effect>

With Console.Write(xmlElement.Outer) you get everything:

<node>Hello <effect color="pink">World</effect></node>

With Console.Write(xmlElement.Value) you get nothing, because Value always returns null for an XML element.

like image 4
Nicolas Raoul Avatar answered Oct 20 '22 03:10

Nicolas Raoul