Results 1 to 5 of 5

Thread: QDomDocument doesn't accept parentheses when parsing an xml file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QDomDocument doesn't accept parentheses when parsing an xml file

    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:
    Qt Code:
    1. QFile file(QApplication::applicationDirPath()+"/a.xml");
    2. file.open(QIODevice::ReadOnly | QIODevice::Text);
    3. doc.setContent(&file);
    4. file.close();
    To copy to clipboard, switch view to plain text mode 

    xml file:
    Qt Code:
    1. <root>
    2. <node(>
    3. </node(>
    4. </root>
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by hind; 3rd August 2014 at 08:03. Reason: updated contents

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDomDocument doesn't accept parentheses when parsing an xml file

    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

  3. #3
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument doesn't accept parentheses when parsing an xml file

    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?
    Last edited by hind; 3rd August 2014 at 08:50. Reason: reformatted to look better

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomDocument doesn't accept parentheses when parsing an xml file

    Convert them to another set of characters before passing the data to QDomDocument.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDomDocument doesn't accept parentheses when parsing an xml file

    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.

Similar Threads

  1. Parenthesis Comparision with Enter key Event
    By parulkalra14 in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2014, 10:39
  2. Replies: 2
    Last Post: 26th November 2013, 05:15
  3. QTextEdit parenthesis matcher works - but only partially
    By heinzkde in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2010, 12:31
  4. QDomElement
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2007, 12:55
  5. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.