[Gambas-user] gb.xml feature request
adamnt42 at ...626...
adamnt42 at ...626...
Tue Apr 7 01:24:12 CEST 2015
On Tue, 07 Apr 2015 00:01:02 +0200
"Adrien Prokopowicz" <adrien.prokopowicz at ...626...> wrote:
> Le Sun, 05 Apr 2015 04:58:05 +0200, adamnt42 at ...626...
> <adamnt42 at ...626...> a écrit:
>
> > @Adrien Prokopowicz ?
> >
> > I ask for an enhancement to XMLNode (and descendants). Currently the
> > TextContent property returns the concatenated text of the currenode and
> > all child nodes thereof. What I want to get is the text of the current
> > node only, ignoring any child nodes.
> >
> > Dim sText as String
> > Dim hElt as XMLElement ' = some node
> > sText = hElt.GetLocalTextContent()
> >
> > i.e. a new method to return just the local node text.
> >
> > I think this requires modifying the serializer class
> > GBGetXMLTextContent() method to avoid descending in to the child nodes
> > but it is far beyond my C++ abilities and the attempts I made are too
> > embarrassing to reveal. :-(
> >
> > tia
> > bruce
> >
>
> XML elements do not actually have text. All they have are child nodes,
> that can be XML text nodes (represented by the XmlTextNode class).
>
> Let's say you have the following XML structure :
>
> <p>Hello <em>world</em> ! :-)</p>
> | ^ | ^ | ^ |
> | | | XmlText | | |
> | XmlText|=XmlElement=| XmlText |
> | |
> |========= XmlElement ==========|
>
> (XmlText should be XmlTextNode, but it doesn't fit on the diagram)
>
> By definition (according to the W3C), the TextContent property of
> an XML element contains the text content of all the child nodes
> (and therefore all descendants if some child nodes are elements).
>
> If I understood correctly, you would like to only retreive the text
> "Hello ! :-)" in the case of the above structure.
> What you should do is iterating over the element's nodes, and
> retreiving only the text content of the XmlTextNodes, which is easily
> feasible in pure Gambas, like so :
>
> Dim hElement As XmlElement '= some element
> Dim hNode As XmlNode
> Dim sText As String
>
> For Each hNode In hElement.ChildNodes
> If hNode Is XmlTextNode Then sText &= hNode.TextContent
> Next
>
> Print sText 'Prints : "Hello ! :-)"
>
> Regards,
> --
> Adrien Prokopowicz
>
Aaah! Thanks Adrien (doubly)!
First, that is the solution.
Secondly, your example highlighted a condition that I haven't encountered / envisaged.
regards
bruce
--
B Bruen <adamnt42 at ...3379... (sort of)>
More information about the User
mailing list