Question

I'm having a hard time getting the correct value from the innertext of an XElement. First, here's the XML that I'm using. This is a copy of our production data that results from a process in our workflow. In other words, I can't change the XML, I can only parse it. The element whose innertext I'd like to get has data inside that looks like XML, but it isn't. It is straight text from the tool that produced the XML. The element is called <creatorshapeutildata:

Picture of XML data

Here is the line of code I've tried:

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

I've also tried this:

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

I've also tried this:

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

Unfortunately, the value that gets returned in every case looks like this:

33012-1true#FFFF003#FFFFFF2743337743358

I need the value returned to look like this:

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

This piece I'm working on is part of a larger program that uses XDocument, XElement, etc. I know an XmlElement has an InnerText property, but I think XElement does not, since I can't seem to find it in Intellisense.

So, is there any possible way to grab the exact text between the creatorshapeutil tags?

Was it helpful?

Solution

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

You can get the content including the outer node by calling element.ToString().

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top