I have 2 documents, one is an invalid one (or at least i think it is invalid), the other just fine, for both cases the XML parser does not report any problems and generates a weird result for the "invalid" document, the code to test is simple and very "spaghetti like" (as Jules once said about my example code), it is done on purpose for this post:
File goodFile = File ("c:\\devel\\valid.xml"); File badFile = File ("c:\\devel\\invalid.xml"); XmlDocument goodDocument (goodFile); XmlDocument badDocument (badFile); XmlElement *goodRootElement = goodDocument.getDocumentElement(); XmlElement *badRootElement = badDocument.getDocumentElement(); if (goodRootElement != nullptr) { Logger::writeToLog ("goodRootElement is valid, has ["+String(goodRootElement->getNumChildElements())+"] children"); Logger::writeToLog (goodRootElement->createDocument(String::empty)); Logger::writeToLog ("parser errors: ["+goodDocument.getLastParseError()+"]"); } else { Logger::writeToLog ("goodRootElement is invalid"); Logger::writeToLog ("parser errors: ["+goodDocument.getLastParseError()+"]"); } if (badRootElement != nullptr) { Logger::writeToLog ("badRootElement is valid, has ["+String(badRootElement->getNumChildElements())+"] children"); Logger::writeToLog (badRootElement->createDocument(String::empty)); Logger::writeToLog ("parser errors: ["+badDocument.getLastParseError()+"]"); } else { Logger::writeToLog ("badRootElement is invalid"); Logger::writeToLog ("parser errors: ["+badDocument.getLastParseError()+"]"); }
Now the invalid and valid XML documents are:
<?xml version="1.0" encoding="UTF-8"?> <root> <child1 property1="value" /> <child2 -- None="invalid property"> <subChild property="value" /> <subChild property="value" /> </child2> <child3 property3="value" /> <child4 property4="value" /> </root>
-
<?xml version="1.0" encoding="UTF-8"?> <root> <child1 property1="value" /> <child2 property2="value" /> <child3 property3="value" /> <child4 property4="value" /> </root>
output from the piece of code i posted:
[debug]goodRootElement is valid, has [4] children [debug]<?xml version="1.0" encoding="UTF-8"?> [debug]<root> [debug] <child1 property1="value"/> [debug] <child2 property2="value"/> [debug] <child3 property3="value"/> [debug] <child4 property4="value"/> [debug]</root> [debug]parser errors: [] [debug]badRootElement is valid, has [5] children [debug]<?xml version="1.0" encoding="UTF-8"?> [debug]<root> [debug] <child1 property1="value"/> [debug] <child2/>one="invalid property"> [debug]		<subChild property="value"/> [debug] <subChild property="value"/> [debug]</root> [debug]parser errors: []
output from firefox for the invalid xml only:
XML Parsing Error: not well-formed Location: file:///C:/devel/invalid.xml Line Number 5, Column 10: <child2 -- None="invalid property"> ----------------^
output for xmlvalidator.com
5: 10 Element type "child2" must be followed by either attribute specifications, ">" or "/>"
My problem is that JUCE is not saying anything, it's just dropping the children of the guilty child element, so my document does not open and does not report any errors that something went wrong. I know that i should never have a property like that but i allowed Lua to interface with my program and people do weird stuff and this happens (very very rarely).
Any suggestions?