On Tue, 07 Apr 2015 00:01:02 +0200 "Adrien Prokopowicz" <adrien.prokopow...@gmail.com> wrote:
> Le Sun, 05 Apr 2015 04:58:05 +0200, adamn...@gmail.com > <adamn...@gmail.com> 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 <adamn...@gnail.com (sort of)> ------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user