xml error or parsing error?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Cristian
Posts: 55
Joined: Fri Nov 25, 2005 12:02 pm

xml error or parsing error?

Post by Cristian »

Basically what I have is a level manager with a function that is supposed to load a level from an XML file formatted like this:

Code: Select all

<level>
<Property isWorld="0"/>
<Property x="-10" y="-10" z="-10" x2="10" y2="10" z2="10"/>
	<room>
		<Property name = "room"/>
		<Property visible = "1"/>
		<display>
		<Mesh file="HALL.3ds" scale="10" position_x="0" position_y="0" position_z="0" rotation_x="0" rotation_y="0" rotation_z="0" material="0"/>
		<Mesh file="HALL_LIT.3ds" scale="10" position_x="0" position_y="0" position_z="0" rotation_x="0" rotation_y="0" rotation_z="0" material="1"/>
		</display>
	</room>
</level>
The problem is, it skips the "<Property />" and "<Mesh/>" tags without reading their content. Could anyone please lend a hand ?
the function is here:

Code: Select all

void cLevelManager::loadFromXML(irr::IrrlichtDevice* device, char* filename)
{
    bool visible;
    char* name;

    printf("loading \n");
    int scale, pos[2], rot[2];

    irr::io::IXMLReader* m_pXMLreader =device->getFileSystem()->createXMLReader(filename);

    if (m_pXMLreader == 0)
    {
        printf("error in level file \n");
        return;
    }else printf("reading \n");

    while(m_pXMLreader->read())
    {
        printf("searching... \n");
        if(m_pXMLreader->getNodeType() == irr::io::EXN_ELEMENT)
        {
            printf("found node \n");
            if(core::stringw("level") == m_pXMLreader->getNodeName())
                if (core::stringw("Property") == m_pXMLreader->getNodeName())
                {
                    printf("found level property \n");
                    if (m_pXMLreader->getAttributeValueAsInt(L"isWorld") == 0) m_bIsWorldMap = false; else m_bIsWorldMap = true;
                    Level_AABB = irr::core::aabbox3df(m_pXMLreader->getAttributeValueAsFloat (L"x"), m_pXMLreader->getAttributeValueAsFloat (L"y"), m_pXMLreader->getAttributeValueAsFloat (L"z"), m_pXMLreader->getAttributeValueAsFloat (L"x2"), m_pXMLreader->getAttributeValueAsFloat (L"y2"), m_pXMLreader->getAttributeValueAsFloat (L"z2"));
                }
              if(core::stringw("room") == m_pXMLreader->getNodeName())
              {
                  printf("found room \n");
                  if (core::stringw("Property") == m_pXMLreader->getNodeName())
                  {
                  printf("found room property \n");
                  name = (char*)m_pXMLreader->getAttributeValue(L"name");
                  if (m_pXMLreader->getAttributeValueAsInt (L"visible") == 0) visible=false; else visible=true;
                  }
                  addRoom(name, visible);
              }
                if (core::stringw(L"display") == m_pXMLreader->getNodeName())
                {
                    printf("found display \n");
                    if (core::stringw(L"Mesh") == m_pXMLreader->getNodeName())
                    {
                        printf("found mesh \n");
                        name  = (char*)m_pXMLreader->getAttributeValue(L"filename");
                        scale = m_pXMLreader->getAttributeValueAsInt(L"scale");
                        pos[0] = m_pXMLreader->getAttributeValueAsInt(L"position_x");
                        pos[1] = m_pXMLreader->getAttributeValueAsInt(L"position_y");
                        pos[2] = m_pXMLreader->getAttributeValueAsInt(L"position_z");
                        rot[0] = m_pXMLreader->getAttributeValueAsInt(L"rotation_x");
                        rot[1] = m_pXMLreader->getAttributeValueAsInt(L"rotation_y");
                        rot[2] = m_pXMLreader->getAttributeValueAsInt(L"rotation_z");

                        scale=m_pXMLreader->getAttributeValueAsInt(L"material");
                        switch (scale)
                        {
                            case 0: m_cuRoomArray[m_cuRoomArray.size()-1]->addVisibleMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale), irr::video::EMT_SOLID); break;
                            case 1: m_cuRoomArray[m_cuRoomArray.size()-1]->addVisibleMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale), irr::video::EMT_TRANSPARENT_ADD_COLOR); break;
                            case 2: m_cuRoomArray[m_cuRoomArray.size()-1]->addVisibleMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale), irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL); break;
                        }
                    }
                }

                if (core::stringw(L"collision") == m_pXMLreader->getNodeName())
                {
                    printf("found collision \n");
                    if (core::stringw(L"Mesh") == m_pXMLreader->getNodeName())
                    {
                        printf("found col mesh \n");
                        name  = (char*)m_pXMLreader->getAttributeValue(L"filename");
                        scale = m_pXMLreader->getAttributeValueAsInt(L"scale");
                        pos[0] = m_pXMLreader->getAttributeValueAsInt(L"position_x");
                        pos[1] = m_pXMLreader->getAttributeValueAsInt(L"position_y");
                        pos[2] = m_pXMLreader->getAttributeValueAsInt(L"position_z");
                        rot[0] = m_pXMLreader->getAttributeValueAsInt(L"rotation_x");
                        rot[1] = m_pXMLreader->getAttributeValueAsInt(L"rotation_y");
                        rot[2] = m_pXMLreader->getAttributeValueAsInt(L"rotation_z");

                        m_cuRoomArray[m_cuRoomArray.size()-1]->addCollisionMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale));
                    }
                }

            }
        }
        //TO DO: de continuat cu citirea fisierului XML
    printf("done \n \n");
    delete m_pXMLreader;
}
EDIT: I reformatted the post.
Elise
Posts: 48
Joined: Tue Jul 19, 2005 6:30 am
Contact:

Post by Elise »

I think IrrXML only supports 5 attributes per XML node, and you use quite a bit more in some nodes. Not sure if that's the cause of your problems, but you might try dividing some of the nodes to several ones.
Instead of:

Code: Select all

<Property x="-10" y="-10" z="-10" x2="10" y2="10" z2="10"/>
Something like:

Code: Select all

<Property>
  <Pos1 x="-10" y="-10" z="-10" />
  <Pos2 x="10" y="10" z="10" />
</Property>
Cristian
Posts: 55
Joined: Fri Nov 25, 2005 12:02 pm

Post by Cristian »

The problem was with both the file and the parser:
- instead of getting full strings it got just the first character, so i used an actual XML editor and outputted a new file.
- instead of IRRLICHT irrXML I used the separated release of irrXML

Level Prototype file

Code: Select all

<?xml version="1.0"?>
<level isWorld="0">
	<level_aabbox x="" y="" z="" x1="" y1="" z1=""/>
	<room name="" id="" visible="">
		<aabbox x="" y="" z="" x1="" y1="" z1=""/>
		<display>
			<d_mesh file="" scale="" material="">
				<d_pos x="" y="" z=""/>
				<d_rot x="" y="" z=""/>
			</d_mesh>
		</display>
		<collide>
			<c_mesh file="" scale="" use_aabbox="">
				<c_pos x="" y="" z=""/>
				<c_rot x="" y="" z=""/>
			</c_mesh>
		</collide>
	</room>
</level>
Post Reply