Bug(?) in irrXML 1.2

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
Bander
Posts: 2
Joined: Sat Dec 24, 2005 4:56 pm
Location: Netherlands

Bug(?) in irrXML 1.2

Post by Bander »

Given a simple XML file containing:

Code: Select all

<parent>
  <child></child>
</parent>
You'll see IXMLReader return the following nodes:
  • EXN_ELEMENT "parent"
    EXN_TEXT
    EXN_ELEMENT "child"
    EXN_ELEMENT_END "child"
    EXN_TEXT
    EXN_ELEMENT_END "parent"
The EXN_TEXT nodes being the whitespace in between the elements. This is all as expected. However, with the completely equivalent XML file containing:

Code: Select all

<parent>
  <child />
</parent>
IXMLReader returns the following nodes:
  • EXN_ELEMENT "parent"
    EXN_TEXT
    EXN_ELEMENT "child"
    EXN_TEXT
    EXN_ELEMENT_END "parent"
Note the missing EXN_ELEMENT_END node. When finding an empty element, irrXML does not emit a EXN_ELEMENT_END node for that element.

This behavior sort of makes sense since there wasn't an actual end element in the XML stream, but it makes it very hard to parse through XML files which may optionally contain empty elements, and I consider it a bug.

Writing a fix for this isn't very difficult, but before I do I'd like to ask: Does the forum agree that this is an actual bug? Or are there people relying on this behavior? Any other comments?
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

the behavior should be the same in either case, so yeah, I'd say its a bug. This is got to be some standards compliance issue. I hope to use irrxml outside of config files.
Bander
Posts: 2
Joined: Sat Dec 24, 2005 4:56 pm
Location: Netherlands

Post by Bander »

The quick fix is even simpler than I thought. In CXMLReaderImpl.h at line 67, change the read() method to:

Code: Select all

	//! Reads forward to the next xml node. 
	//! \return Returns false, if there was no further node. 
	virtual bool read()
	{
		// if previous node was an empty element, emit an end node
		if (IsEmptyElement == true) {
			CurrentNodeType = EXN_ELEMENT_END;
			IsEmptyElement = false;
			return true;
		}

		// if not end reached, parse the node
		if (P && (unsigned int)(P - TextBegin) < TextSize - 1 && *P != 0)
		{
			parseCurrentNode();
			return true;
		}

		_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
		return false;
	}
Certainly beats querying isEmptyElement() for every node.
Post Reply