The function GetText()
won't give you the actual name of the node in question, but the text inside the node. For instance, invoking GetText()
on this hypothetical node
<node>This is text!</node>
will yield "This is text!" as a const char*
or a const std::string&
depending on how you compile. See the API reference of TiXmlElement.
If you want to query the node name itself, use TiXmlNode::Value()
.
If you want an attribute, simply use Attribute(const char*)
or QueryStringAttribute(...)
on the element. For instance, retrieving and printing the following with the document you provided
std::cout << doc.FirstChildElement ()->FirstChildElement ()->Attribute ("name") << std::endl;
yields "testAPPlication".
In general, see the full documentation of TinyXML first.
EDIT: The following example depicts in a simple, yet ugly way what you need:
TiXmlDocument doc;
if(doc.LoadFile ("test.xml"))
{
TiXmlElement* graphElem = doc.FirstChildElement()->FirstChildElement ()->FirstChildElement ();
TiXmlElement* channelElem = graphElem->FirstChildElement ();
for(; channelElem; channelElem = channelElem->NextSiblingElement ())
{
std::cout << channelElem->Attribute ("producer")
<< " | "
<< channelElem->Attribute ("consumer")
<< std::endl;
}
}
EDIT2: Removed infinite loop and conditional.