TinyXML-2
5.0.1
|
(The XML is an excerpt from "dream.xml").
The structure of the XML file is:
For this example, we want to print out the title of the play. The text of the title (what we want) is child of the "TITLE" element which is a child of the "PLAY" element.
We want to skip the declaration and dtd, so the method FirstChildElement() is a good choice. The FirstChildElement() of the Document is the "PLAY" Element, the FirstChildElement() of the "PLAY" Element is the "TITLE" Element.
We can then use the convenience function GetText() to get the title of the play.
Text is just another Node in the XML DOM. And in fact you should be a little cautious with it, as text nodes can contain elements.
Consider: A Midsummer Night's <b>Dream</b>
It is more correct to actually query the Text Node if in doubt:
Noting that here we use FirstChild() since we are looking for XMLText, not an element, and ToText() is a cast from a Node to a XMLText.