Evyatar
Evyatar

Reputation: 1157

Get XDocument value C#

I have the following XDocument object:

<Field value="&lt;MyTag&gt;BlaBla&lt;/MyTag&gt;" />

I want to get the value with the &lt ; &gt ; etc..What I'm tried:

string value = myXdocumentObject.Element("Field").Attribute("value").Value;

But value is < MyTag>BlaBla< /MyTag>' and not &lt ;MyTag&gt;BlaBla&lt ;/MyTag& gt;

How can i take the value?

Upvotes: 2

Views: 54

Answers (1)

loopedcode
loopedcode

Reputation: 4893

That is default behavior. Value property will decode escaped characters. If you want to have it encoded; you can just re-encode it with HttpUtility.HtmlEncode

var value = HttpUtility.HtmlEncode(myXdocumentObject.Element("Field").Attribute("value").Value);

Upvotes: 4

Related Questions