IrrXML Error

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
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

IrrXML Error

Post by AlexL »

So lately, I have been attempting to use IrrXML to load data for configuration and scene setup files. But when attempting to use it to load network information from the XML, I get an error/bug where it repeates itself five times; with the third attempt being the only sucessful load.

I am not sure if this is being caused due to user inexperiance, but if I had to put money down I would go with that. . . So, if anyone has a spare moment or three; below is an image better describing what I am talking about, the XML source, and the relavent part of the application source. Thank you in advanced to anyone that takes the time to look over this :)

Image

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<!-- irrGame Configuration File -->
<config>
    <graphics driver="EDT_OPENGL" width="800" height="600" depth="32" fullscreen="false" vsync="false" shaders="false" />
    <network port="1024" ip="127.0.0.1" timeout="30" />
</config>

Code: Select all

//SNIP
	m_hXMLConfig = g_pGlobals->pDevice->getFileSystem()->createXMLReaderUTF8("./datas/config.xml");
	if(!m_hXMLConfig)
	{
		CLogger::writeLog("CServer::Init <Failed> : Could not read configuration file.");
		return false;
	}

	// Read through XML Configuration file.
	while(m_hXMLConfig->read())
	{
		switch(m_hXMLConfig->getNodeType())
		{
		case irr::io::EXN_ELEMENT:
			if(strcmp("port",m_hXMLConfig->getNodeName()))
			{
				CLogger::writeLog("CServer::Init() <Note> : Port number found.");
				m_iPort = m_hXMLConfig->getAttributeValueAsInt("port");
				printf("Port number being the following: %i\n",m_iPort);
			}
			break;
		}
	}
	m_hXMLConfig->drop();
//SNIP
Guest

Re: IrrXML Error

Post by Guest »

AlexL wrote:

Code: Select all

//SNIP
	m_hXMLConfig = g_pGlobals->pDevice->getFileSystem()->createXMLReaderUTF8("./datas/config.xml");
	if(!m_hXMLConfig)
	{
		CLogger::writeLog("CServer::Init <Failed> : Could not read configuration file.");
		return false;
	}

	// Read through XML Configuration file.
	while(m_hXMLConfig->read())
	{
		switch(m_hXMLConfig->getNodeType())
		{
		case irr::io::EXN_ELEMENT:
			if(strcmp("port",m_hXMLConfig->getNodeName()))
			{
				CLogger::writeLog("CServer::Init() <Note> : Port number found.");
				m_iPort = m_hXMLConfig->getAttributeValueAsInt("port");
				printf("Port number being the following: %i\n",m_iPort);
			}
			break;
		}
	}
	m_hXMLConfig->drop();
//SNIP
Ok. There are two problems here. First, port is an attribute, and m_hXMLConfig->getNodeName() will never ever return "port". Second, strcmp will return 0 if the two strings are equal. Try this:

Code: Select all

if(strcmp("network",m_hXMLConfig->getNodeName()) == 0)
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

Post by AlexL »

Thank you for the help Guest, seems as though the only error here was my lack of understanding with IrrXML :? Anyways, all is good now; thank you again :D
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

^^ Above Guest = me.

Anyways, no problem. I just got done messing with IrrXML and all its little nuances, so it was all very fresh in my mind. :D
Post Reply