Parenthesis in ofXml


#1

Hello,
I spend a lot of time tracking what error I was into, and I discovered why:

ofXml xml;
xml.appendChild("ChildName").setAttribute("value(x1000)", 1000);
xml.save("FileName.xml");
xml.load("FileName.xml");

wouldn’t load. The save is perfectly fine though.

It seems that the parenthesis are the problem “value(x1000)”. Altough I don’t think this should be an illegal character in XML 1.0:
https://www.w3.org/TR/xml/#charsets

I was hoping for some thoughts before adding an issue. It might be pugiXML’s fault also.


#2

Also I notice that there is no way of checking if a tag or an attribute exists,
and you go straight into a crash if you try a non-existing tag/attribute.
ofXmlSettings has tagExists() and attributeExists()
:slight_smile:
If someone knows a way to check, I would be glad to read it !


#3

to check you can just do:

auto child = xml.getChild("child");
if(child){
    auto attribute = child.getAttribute("attribute");
    if(attribute){
         attribute...
    }
}

it’s indeed weird that parenthesis get added but not read so it might be a bug in the library we use to parse xml. i’ll take a look but can you open a github issue?


#4

Alright !
Thanks !
I don’t know if that makes sense to implement a operator bool() to getChildren() too ?
I also opened a issue yesterday about getFloatValue() yesterday.