Internal text from XElement?

I find it difficult to get the correct value from the inner text of the XElement. First, here is the XML that I use. This is a copy of our production data, which is the result of a process in our work process. In other words, I cannot change the XML, I can only parse it. The element whose inner text I would like to receive has data inside that looks like XML, but it is not. This is plain text from the tool that created the XML. The item is called <creatorshapeutildata :

Picture of XML data

Here is the line of code I tried:

 CreatorShapeUtilData = element.Descendants("creatorshapeutildata").Single().Value; 

I also tried this:

 CreatorShapeUtilData = element.Descendants("creatorshapeutildata").First().Value; 

I also tried this:

 CreatorShapeUtilData = element.Element("creatorshapeutildata").Value; 

Unfortunately, the value returned in each case is as follows:

33012-1true#FFFF003#FFFFFF2743337743358

I need the return value to look like this:

 "<creatorData type="object"><type type="int">33012</type>..." 

This part I'm working on is part of a larger program using XDocument, XElement, etc. I know that XmlElement has an InnerText property, but I think XElement does not, because I cannot find it in Intellisense.

So, is there a possible way to capture the exact text between creatorshapeutil tags?

+6
source share
1 answer

You are trying to get the exact opposite of the InnerText / Value properties: raw XML content.

You can get the contents, including the external node, by calling element.ToString() .

If you want to exclude an external tag, you can call String.Concat(element.Nodes()) .

+18
source

All Articles