Sign in to follow this  

Reading XML values [Figured something out...]

This topic is 3144 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

This topic is 3144 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this