I am having difficulties with RapidXML only parsing the first line of my file (or so it appears). When I feed in a sample file, it merely gets the first node ("map") and nothing else. I set a breakpoint in Xcode after the parsing to inspect the result and there seems to be NULL values for majority of the attributes. Does anyone have any recommendations on how to fix this? It is my understanding that the parser is suppose to produce some form of tree like structure. Perhaps I have a misunderstanding of the resulting data structure?
Here is my usage:
#include <iostream> #include "rapidxml_utils.hpp" using namespace std; int main(){ rapidxml::file<> xmlFile("sample.txt.xml"); rapidxml::xml_document<> doc; doc.parse<0>(xmlFile.data()); cout << "Name of my first node is: " << doc.first_node()->name() << "\n"; rapidxml::xml_node<> *node = doc.first_node("map"); cout << "Node map has value " << node->value() << "\n"; for (rapidxml::xml_attribute<> *attr = node->first_attribute(); attr; attr = attr->next_attribute()) { cout << "Node foobar has attribute " << attr->name() << " "; cout << "with value " << attr->value() << "\n"; } } Here is an example of the file I am trying to parse:
<?xml version="1.0" encoding="utf-8"?> <map> <room> <name>Entrance</name> <description>You find yourself at the mouth of a cave</description> <item>torch</item> <trigger> <type>permanent</type> <command>n</command> <condition> <has>no</has> <object>torch</object> <owner>inventory</owner> </condition> <print>*stumble* need some light...</print> </trigger> <border> <direction>north</direction> <name>MainCavern</name> </border> </room> </map>
No comments:
Post a Comment