PDA

View Full Version : QDomDocument doesn't accept parentheses when parsing an xml file



hind
3rd August 2014, 05:34
When there is a parenthesis contained in a node of xml file the QDomDocument::setContent gives error "error occurred while parsing element". The error column is right where the parenthesis is. Remove all parentheses and there is no error.

Codes:

QFile file(QApplication::applicationDirPath()+"/a.xml");
file.open(QIODevice::ReadOnly | QIODevice::Text);
QDomDocument doc;
doc.setContent(&file);
file.close();

xml file:

<root>
<node(>
</node(>
</root>

I have googled but found no restriction to parentheses usage in xml file. And I can save nodes with parentheses successfully, with QDomDocument::save. How can I retrieve it?

ChrisW67
3rd August 2014, 09:08
QDomDocument is telling you that the input is malformed because parentheses are not permitted in an XML element Name: http://www.w3.org/TR/REC-xml/#sec-starttags

hind
3rd August 2014, 09:49
Well it looks like my manual does not mention that. And it's strange that the QDomDocument allows it when saving the doc to xml files.
So what should I do if the users insist putting parentheses in the element names?

wysota
3rd August 2014, 09:59
Convert them to another set of characters before passing the data to QDomDocument.

d_stranz
3rd August 2014, 23:38
Or train your users to correctly specify XML element names. Refuse to permit anything except allowed characters in XML strings and put up an error dialog if the user types a character that isn't allowed by the standard.