irrXML

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
BirdaoGwra
Posts: 11
Joined: Sat Jan 30, 2016 5:47 am

irrXML

Post by BirdaoGwra »

Hi,

Code: Select all

<object>
   <attributes>
      <data name="adhar" value="non" />
      <data name="barbu" value="non" />
      <int name="Id" value="16" />
      <string name="name" value="Ashara" />
   </attributes>
</object>
I am having a little problem to parse the data tag. I want to parse it by its tag. How do I do it?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: irrXML

Post by Mel »

when you use the XML reader, you read "nodes" from the XML file. These nodes have names so you can know where you are at each moment and have the attributes the XML tag might have. What are you trying to do? perhaps posting some code would help big deal
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
BirdaoGwra
Posts: 11
Joined: Sat Jan 30, 2016 5:47 am

Re: irrXML

Post by BirdaoGwra »

Sorry, I typed that from my phone so could not explain it.
Say, I have a xml file like -

Code: Select all

 
<npc>
 
   <object>
      <attributes>
         <data name="one" value="non" />
         <data name="two" value="non" />
         <int name="id" value="-1" />
         <string name="name" value="Ashara" />
      </attributes>
   </object>
 
   <object>
      <attributes>
         <data name="one" value="non" />
         <data name="two" value="bone" />
         <int name="id" value="-1" />
         <string name="name" value="Talim" />
      </attributes>
   </object>
 
</npc>
 
These are two Npc object with their attributes.

Code: Select all

 
while(xml->read())
{
   switch(xml->getNodeType())
   {
      case EXN_ELEMENT:
      {
         if(tag.equals_ignore_case(xml->getNodeName())
         {
            IAttributes* attr = fs->createEmptyAttributes(driver);
            attr->read(xml);
 
            // Load Nps data
            // Don't know
 
            // Load id and names
            s32 id = attr->getAttributesAsInt("id");
            stringc name = attr->getAttributeAsString("name");
 
            // Create Npcs
            -----------------
            -----------------
         }
      }
   }
}
 
How do I load the data tag from each objects cos it is required while creating Nps?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: irrXML

Post by Mel »

Irrlicht xml reads "nodes" (tags, whether opening or closing), so when you read a tag (a node) it has immediately the attributes, if any, you just have to query them. I suggest you to read the source code of the irr scene loader to understand better how Irrlicht handles the XML files :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: irrXML

Post by CuteAlien »

What is the value of "tag"? Is it "Attributes"?
Note that there is also an xml reader example in Irrlicht.
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
BirdaoGwra
Posts: 11
Joined: Sat Jan 30, 2016 5:47 am

Re: irrXML

Post by BirdaoGwra »

Sorry for late reply. I solved it, thank you.
Post Reply