xml attribute with multiple values

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
Vel0city
Posts: 4
Joined: Sun Sep 25, 2016 2:22 pm

xml attribute with multiple values

Post by Vel0city »

Hello,
I stored vector and color information in xml and I'm not sure how to read them using the irrXML reader as the according attributes have multiple values.
An example looks like this:

Code: Select all

<Light color="0.7, 0.7, 0.7, 1.0"/>
I know it could be all read to a string using getAttributeValue("color"). Is there a possibility to get the numbers out of an irrlicht string?
the getAttributeValueAsFloat command sadly only returns the first number.

An older discussion from 2007 didn't contain information which I could understand on my level.

Can somebody point me in the right direction how this could be done?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: xml attribute with multiple values

Post by CuteAlien »

Could probably do something like:

Code: Select all

 
float r,g,ba;
swscanf_s( xml->getAttributeValueSafe(L"color"), L"%f,%f,%f,%f", &r, &g, &b, &a);
 
Untested and instead of swscanf_s you probably need swscanf on non VS platforms.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
bkeys
Posts: 42
Joined: Sat Feb 27, 2016 9:06 pm

Re: xml attribute with multiple values

Post by bkeys »

You may also be better off using an external library for this. Personally I use TinyXML2 for my XML parsing. TinyXML2 is also under a permissive license so you can use it for any purpose as well.
- Brigham Keys, Esq.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: xml attribute with multiple values

Post by CuteAlien »

@bbeys: Tinyxml is a DOM reader while Irrlicht xml is a SAX reader. Both have their use - just different approaches to working with xml (you can implement a DOM reader on top of a SAX reader).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply