Advertisement Jump to content
Sign in to follow this  

Reading XML values [Figured something out...]

This topic is 3548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, im trying to write an XML parser and im stuck on one thing, reading the values into thier appropriate types. Right now i have 3 classes and 2 enums ( but i will probably end up writing more ): XMLAttribute - should contain the name of an attribute and the value of the attribute, numerous XMLAttributes can be nested inside an XMLElement object XMLElement - should contain the name of the element ( eg. <Element></Element> == Element ) plus a std::vector of XMLAttribute and another std::vector of its child XMLElements* XMLStream - The class that interacts with the XML file and constructs ( i think ) a tree structure of elements with thier attributes values and so on. Also contains 2 special attributes called mVersion and mEncoding. So yeah thats what ive got so far, but i need to know how i should go about getting the actual data cast into the appropriate type, seeing as the elements and attributes are constructed inside the XMLStream class, anyone? Thanks in advance EDIT: nevermind, im going to try reading the data in as a string and use std::stringstream to convert it into the data type i need when i call As<DataType>( ) on either an element or attribute. much like the HLSL does with the effect and technique classes in direct3d ( i think ) Eg. XMLStream SomeStream( ... ); XMLElement* SomeElement; SomeElement = SomeStream.Element( "Window" ); std::string caption = SomeElement->Attribute( "Caption" )->AsString( ); int x = SomeElement->Attribute( "Xpos" )->AsInteger( ); int y = SomeElement->Attribute( "Ypos" )->AsInteger( ); something along those lines anyhow... [Edited by - CodeCriminal on May 4, 2009 1:37:26 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!