I'm having trouble understanding how to do very basic, straightforward manipulation of data pulled from an .xml file and the tutorial didn't really give examples that helped me out. Say I have this data:
_______________________-
<?xml version="1.0" standalone=no>
<!-- Monty Python's Holy Grail text adventure version 1.0 -->
<items>
<item name="SHRUBBERY" description="100 pounds of decorative wood that is useless for combat.">
<item name="SWORD" description="A scimitar that a watery tart lobbed at you.">
<item name="MAP" description="A map that reads 'North, West, South, West'. You’re not expect to follow it.">
<item name="BOOK" description="A Book of Knowledge that resembles Wikipedia. Has a full section on Laden Swallows.">
<item name="ORB" description="A fiery orb that’s been said to warm the hearts of even the coldest women.">
</items>
___________________________
1) check your error codes in the source (especially from the LoadFile)
2) check your source XML in a browser (IE, Firefox) which will show errors in XML visually.
lee
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey,
I'm having trouble understanding how to do very basic, straightforward manipulation of data pulled from an .xml file and the tutorial didn't really give examples that helped me out. Say I have this data:
_______________________-
<?xml version="1.0" standalone=no>
<!-- Monty Python's Holy Grail text adventure version 1.0 -->
<items>
<item name="SHRUBBERY" description="100 pounds of decorative wood that is useless for combat.">
<item name="SWORD" description="A scimitar that a watery tart lobbed at you.">
<item name="MAP" description="A map that reads 'North, West, South, West'. You’re not expect to follow it.">
<item name="BOOK" description="A Book of Knowledge that resembles Wikipedia. Has a full section on Laden Swallows.">
<item name="ORB" description="A fiery orb that’s been said to warm the hearts of even the coldest women.">
</items>
___________________________
I have, in my C++ file:
TiXmlDocument doc( "HolyGrail.xml" );
doc.LoadFile();
TiXmlElement* itemList = doc.FirstChildElement("items");
TiXmlElement* itemEntry = itemList->FirstChildElement("item");
cout<<itemEntry->Attribute("name"); //this works
itemEntry = itemEntry->NextSiblingElement("item");
cout<<itemEntry->Attribute("name"); //this doesn't work.
I must have a fundamental misunderstanding here. If NextSiblingElement is not the way to access other "item" elements, what is? Please help.
Thanks in advance.
Perhaps your "item" tags are not closed...
Yep, missing close tags looks like the problem to me. TinyXML thinks you have:
<items>
<item name="SHRUBBERY" ...
<item name="SWORD" ...
<item name="MAP" ...
<item name="BOOK" ...
<item name="ORB" ...
<!-- these are all missing
</item>
</item>
</item>
</item>
</item>
-->
</items>
General tips:
1) check your error codes in the source (especially from the LoadFile)
2) check your source XML in a browser (IE, Firefox) which will show errors in XML visually.
lee