xml->getNodeName() gives wrong values....why?

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

xml->getNodeName() gives wrong values....why?

Post by Masterhawk »

I try to read a xml file, so I want to check the nodeNames, but with the code below the the method xml->getNodeName() only gives the first char of every Element

Code: Select all

IXMLReader* xmlr = device->getFileSystem()->createXMLReader("./bahn3.xml");
                          
                          while(xmlr && xmlr->read())
                          {                                
                             int c = -1;
                             //const wchar_t* nodename = xmlr->getNodeName();
                             wchar_t nodename[255];
                             swprintf(nodename,L"");
                             swprintf(nodename,xmlr->getNodeName());
                             printf("nodename1:%s\n",nodename);
                             
                             if (core::stringw("Entities") == nodename)
                             {
                                   c = xmlr->getAttributeValueAsInt(L"count");
                                   printf("%i\n",c);
                             }
                             else
                             {
                             for(int i=0;i<c;i++)
                             {   
                                 IEntity Ent;    
                                 for(int j=0;j<2;j++)
                                 {     
                                    wchar_t EntName[255];
                                    swprintf(EntName,L"Entity%i-%i",i,j);
                                    if (EntName == nodename)
                                    { 
                                       printf("Testin mark#1");
                                       if(j==0) //read partI of the current entity
                                       {
                                          Ent.X = xmlr->getAttributeValueAsFloat(L"posX");
                                          Ent.Y = xmlr->getAttributeValueAsFloat(L"posY");
                                          Ent.Z = xmlr->getAttributeValueAsFloat(L"posZ");
                                          Ent.Box.offX = xmlr->getAttributeValueAsFloat(L"offX");
                                          Ent.Box.offZ = xmlr->getAttributeValueAsFloat(L"offZ");
                                          printf("%d %d",Ent.X,Ent.Y);
                                       }
                                       else if(j==1)
                                       {
                                          Ent.Box.length = xmlr->getAttributeValueAsFloat(L"length");
                                          Ent.Box.width = xmlr->getAttributeValueAsFloat(L"width");
                                          Ent.Box.height = xmlr->getAttributeValueAsFloat(L"height");
                                          Ent.TYPE = xmlr->getAttributeValueAsInt(L"type"); 
                                       }
                                    } //end EntName    
                                 } //end FOR j
                                 
                             }//end FOR i
                             } //end if
                             printf("nodename:%s\n",nodename);                   
                          }
console output:

Code: Select all

nodename1:
nodename:
nodename1:E
2
nodename:E
nodename1:E
nodename:E
nodename1:E
nodename:E
nodename1:E
nodename:E
nodename1:E
nodename:E
nodename1:x
nodename:x
the xml file

Code: Select all

<?xml version="1.0"?>
<Entities count="2" />
<Entity0-0 posX="0" posY="0" posZ="0" offX="-10" offZ="-10" />
<Entity0-1 length="0" width="0" height="0" type="0" />
<Entity1-0 posX="0" posY="0" posZ="0" offX="-10" offZ="-10" />
<Entity1-1 length="50" width="20" height="80" type="1" />
</xml>
Does anyone know an answer why only the first char is returned by the function.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Because it's wchar_t and you write char* which makes the NULL byte of the wchar_t terminate the string.
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

Thx....I've found the mistake... :oops: ...just forgot the "l" :oops: :oops:

Code: Select all

printf("%ls",nodename);
Post Reply