[Gambas-user] Getting the "un-specialed" XMLElement.TextContent string

Fabien Bodard gambas.fr at ...626...
Wed Jun 25 09:21:30 CEST 2014


Le 25 juin 2014 01:04, "B Bruen" <bbruen at ...2308...> a écrit :
>
> On Tue, 24 Jun 2014 16:36:11 +0200
> "Adrien Prokopowicz" <adrien.prokopowicz at ...626...> wrote:
>
> > 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 &nbsp, &lt, 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
> >
> Adrien,
>
> That's what I thought. But now I found my problem.
>
> The special characters are in the attributes of the element, not in the
text content.  Here's an example:
>
> (racenode is an XMLElement)
>
> ? racenode.Tostring(true)
> <Race RaceNo="8" RaceTime="2014-06-25T15:55:00" RaceName="C,G&E 0 -
68 HANDICAP" Distance="1211" WeatherChanged="N" WeatherCond="3"
WeatherDesc="Showery" TrackChanged="N" TrackCond="5" TrackDesc="Heavy">
> ( inner content excised )
> </Race>
>
> I'm looking at a bit of code that is:
>     $title = raceNode.Attributes["RaceName"]
> which ends up with the raw value, viz
>     C,G&E 0 - 68 HANDICAP
>
> Is there a way to get an attribute value "de-specialed"?
$title = xmlnode.deserialize(raceNode.Attributes["RaceName"])

No? B-)

>
> tia
> Bruce
> --
> B Bruen <bbruen at ...2308...>
>
>
------------------------------------------------------------------------------
> Open source business process management suite built on Java and Eclipse
> Turn processes into business applications with Bonita BPM Community
Edition
> Quickly connect people, data, and systems into organized workflows
> Winner of BOSSIE, CODIE, OW2 and Gartner awards
> http://p.sf.net/sfu/Bonitasoft
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



More information about the User mailing list