[Gambas-user] Getting the "un-specialed" XMLElement.TextContent string
Adrien Prokopowicz
adrien.prokopowicz at ...626...
Tue Jun 24 16:36:11 CEST 2014
Le Tue, 17 Jun 2014 01:37:49 +0200, B Bruen <bbruen at ...2308...> a
écrit:
> (I'm sure I've done this before, but I can't find my prior code nor can
> I find it in either of the help sites.)
>
> I just want to set a string variable to the text content of an element.
> I am almost certain there was a way to have it automatically convert all
> the "special character"s, like  , <, etc etc to their "normal"
> representation. Is there such a function, or was I just dreaming?
>
> tia
> Bruce
>
(Sorry about the late answer, I was quite busy these last few months ...)
The XmlNode.TextContent property is actually what you're looking for : it
defines the node's text content without these entities. For example, this
little code :
Dim doc As New XmlDocument
doc.FromString("<xml>Fish & chips</xml>") 'This can be doc.Open(),
doc.Content = "..." or whatever
Print doc.ToString()
Print doc.Root.TextContent
... will output this :
<?xml version="1.0" encoding="UTF-8"?><xml>Fish & chips</xml>
Fish & chips
Moreover, you have the static couple of methods XmlNode.Serialize() and
XmlNode.Deserialize() that allow you to convert strings back and forth
between the "with entities" and "without entities" representations.
Regards,
--
Adrien Prokopowicz
More information about the User
mailing list