XML Parsing problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Xarshi
Posts: 27
Joined: Sat Feb 28, 2009 6:15 pm

XML Parsing problems

Post by Xarshi »

Ok, so I'm trying to parse some data exported from a program.

Here's a little snippet of some data I'm parsing:

Code: Select all

<Cell ss:StyleID="s21" >
<Data ss:Type="DateTime" >2009-06-19T12:50:00</Data>
</Cell>
<Cell ss:StyleID="s23" >
<Data ss:Type="Number" >1.64846</Data>
</Cell>
I want to be able to read in the date from the first one, and the number from the second one.

Basically, I can read in the ss:Type, but of course, that is set to "DateTime" and "Number". Then I see how many attributes there are, and there is only 1. So my question would have to be how can I get the value, for instance, 1.64846 out of the second cell?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I'm not that familiar with Irrlicht's xml parser though, but did you try to use getAttributeAsFloat and getAttributeAsString ??? ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Xarshi
Posts: 27
Joined: Sat Feb 28, 2009 6:15 pm

Post by Xarshi »

Yup.

It's not that. The values aren't actually stored as an attribute it would seem. It's quite odd. The only attribute associated to each cell is what type of data it is (i.e. number or date).

But yeah, I wouldn't have come here if it was something so easy xD Either way, this is really frustrating to say the least.

This xml file is intended to be imported into excel, but I figured since its xml and reads the same way there wouldn't be much of a problem. I'll take a look around at other xml parsers to see if there is a way.
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

For what I know, "1.64846" isn't an attribute, it's an element.

HTH
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Xarshi wrote:I'll take a look around at other xml parsers to see if there is a way.
I love tinyXML... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

What about this:

Code: Select all

bool XmlTestParser( const core::stringc& loadFilePath )
{
	// assuming loadFilePath points to xml file with the following content:
	//
	// <?xml version="1.0" encoding="utf-8"?>
	// <Cell ss:StyleID="s21" > 
	//	<Data ss:Type="DateTime" >2009-06-19T12:50:00</Data> 
	// </Cell> 
	// <Cell ss:StyleID="s23" > 
	//	<Data ss:Type="Number" >1.64846</Data> 
	// </Cell>

	// init reader 
	irr::io::IXMLReader* reader =  irrlichtDevice->getFileSystem()->CreateXmlReader( loadFilePath.c_str() )  ; 
	if ( !reader ) { return false; } 

	// parse the file until end reached
	core::stringw somestring ;
	core::stringw number ;
	bool timeToReadNumber = false ;

	while( reader && reader->read() )
	{
		switch( reader->getNodeType() )
		{
		case EXN_ELEMENT:
			somestring = reader->getNodeName() ;
			if ( somestring == L"Data" ) 
			{
				somestring = reader->getAttributeValue( L"ss:Type" ) ;
				if ( somestring == L"Number" ) timeToReadNumber = true ;
			}
			break;
		case EXN_TEXT:
			if ( timeToReadNumber ) number = reader->getNodeData() ;
			// do something with your data...
			break;
		}
	}

	delete reader ; reader=0 ;
	return true ;

}
[/code]
Last edited by Arcoroc on Sat Jun 20, 2009 4:01 pm, edited 1 time in total.
L/
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

Valmond wrote:For what I know, "1.64846" isn't an attribute, it's an element.

HTH
Actually it would be the text of the element 'Data'.
L/
Xarshi
Posts: 27
Joined: Sat Feb 28, 2009 6:15 pm

Post by Xarshi »

Thank you a ton, arcoroc. That was the problem. Seems I don't know all that much about xml, hah.
Post Reply