Page 1 of 1

XML Parsing problems

Posted: Fri Jun 19, 2009 9:06 pm
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?

Posted: Fri Jun 19, 2009 10:20 pm
by Acki
I'm not that familiar with Irrlicht's xml parser though, but did you try to use getAttributeAsFloat and getAttributeAsString ??? ;)

Posted: Sat Jun 20, 2009 6:00 am
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.

Posted: Sat Jun 20, 2009 8:58 am
by Valmond
For what I know, "1.64846" isn't an attribute, it's an element.

HTH

Posted: Sat Jun 20, 2009 3:21 pm
by Acki
Xarshi wrote:I'll take a look around at other xml parsers to see if there is a way.
I love tinyXML... ;)

Posted: Sat Jun 20, 2009 3:58 pm
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]

Posted: Sat Jun 20, 2009 4:00 pm
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'.

Posted: Sat Jun 20, 2009 9:25 pm
by Xarshi
Thank you a ton, arcoroc. That was the problem. Seems I don't know all that much about xml, hah.