XML: Can the period be used in the tag name?


#1

Try this simple code,

void foo() { sPath[] = "(MUST BE VALID)"; XmlDocument mDoc(File((const char*)sPath)); XmlElement* pRoot = mDoc.getDocumentElement(); }

If the tag name in the XML document file contains period, pRoot always be NULL. I think period can be used as the tag name as long as it is not the the first character. (so “.text” can’t be but “v1.0” can be)

I found the definition of the “name” below.

Juce can export the XML document like this,

[code]<?xml version="1.0" encoding="UTF-8"?>

[/code]

but can’t load the file.

Best regards,
Masa


#2

Thanks Masa - it’s an easy one to fix, in juce_XmlDocument.cpp:

static inline bool isXmlIdentifierChar_Slow (const tchar c) { return CharacterFunctions::isLetterOrDigit (c) || c == T('_') || c == T('-') || c == T(':') || c == T('.'); }


#3

[quote=“jules”]Thanks Masa - it’s an easy one to fix, in juce_XmlDocument.cpp:

static inline bool isXmlIdentifierChar_Slow (const tchar c) { return CharacterFunctions::isLetterOrDigit (c) || c == T('_') || c == T('-') || c == T(':') || c == T('.'); } [/quote]

If you use a table there, then it will not be “_Slow”…

Even a switch/case will be faster if you specify all symbols up to the latest you watch for…


#4

A table is used in the non-unicode version, and this function is called _slow because it’s the routine used to populate the table.

I’d be very disappointed if a modern compiler didn’t manage to make such a simple if statement as fast as a switch statement. Also, bear in mind that the CharacterFunctions call is checking unicode characters, not just western letters, and that’s not something that you could inline very easily.


#5

Ah, right, populates the table, ignore that then. :slight_smile:

As for the if, the compiler might make it switch’ish, but I would not really think so for that few things. Switch’s have a speed hit due to translating the params into a jump location when the parameters are not increasing uniformly, such as how that one would be. However, a switch statement like:

select(c):
    case 0:
        return false;
    case 1:
        return false;
    case 2:
        return false;
    /* snip */
    case 'a':
        return true;
    case 'b':
        return true;
    case 'c':
        return true;
    /* snip */
    case '_':
        return true;
    /* snip */
    case 255:
        return false;
}

will create the fastest possible switch statement since it generates code that just has a multiply and offset, and returns the value at that location.

A bit more typing that would be, but if interested in speed improvements at all, meh…

Although a static const array of size 256 bytes (bool) so you could just do something like XMLIdentifiers[somechar] would return a true/false for if it is valid and would vastly be the easiest to optimize for the compiler.


#6