Results 1 to 8 of 8

Thread: Problem in XML parsing ";" (semicolon) char

  1. #1
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Problem in XML parsing ";" (semicolon) char

    Hi,
    I have a problem with XML library (Qt DOM class).
    My XML result file is like:

    Qt Code:
    1. <!DOCTYPE myConfigFile>
    2. <myFileSettings>
    3. <option key="key_name" value="key_value" />
    4. </myFileSettings>
    To copy to clipboard, switch view to plain text mode 

    How can I handle a value like "key_value1;key_value2;key_value3" ?
    Now if I use the semicolon char ";" I obtain a wrong XML file...

    Thanks for the help,
    the_bis

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

    Default Re: Problem in XML parsing ";" (semicolon) char

    How about just changing the structure?
    <option key="key_name">key_value1;key_value2;...</option>

    Anyway I don't see a problem why the original idea shouldn't work... What is the exact problem you're facing?

  3. #3
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem in XML parsing ";" (semicolon) char

    Quote Originally Posted by wysota View Post
    How about just changing the structure?
    <option key="key_name">key_value1;key_value2;...</option>
    I have to mantain this structure

    Quote Originally Posted by wysota View Post
    Anyway I don't see a problem why the original idea shouldn't work... What is the exact problem you're facing?
    I have to read a user input with a QLineEdit (this is a remote command to launch via SSH). If I receive a string like "key1;key2;" this is the generated XML file:

    Qt Code:
    1. <!DOCTYPE myConfigFile>
    2. <myFileSettings>
    3. <option key="connection name" value="MyServer" />
    4. <option key="remote command" value="key1
    To copy to clipboard, switch view to plain text mode 

    The file doesn't end correctly: it ends after the first ";" and I have a wrong formatted XML file

    Any help?
    Thanks,
    the_bis

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

    Default Re: Problem in XML parsing ";" (semicolon) char

    Quote Originally Posted by the_bis View Post
    I have to read a user input with a QLineEdit (this is a remote command to launch via SSH).
    In that case I even stronger suggest to use my suggestion and even wrap everything in a CDATA section. If you don't do that, you're asking for trouble. The user can enter virtually anything as a command (including characters ">", "<" which can't be part of attribute values). So either you encode the data (either in some completely mangled form or using SGML entities) in attribute values or you have to use CDATA.

  5. #5
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem in XML parsing ";" (semicolon) char

    Quote Originally Posted by wysota View Post
    In that case I even stronger suggest to use my suggestion and even wrap everything in a CDATA section. If you don't do that, you're asking for trouble. The user can enter virtually anything as a command (including characters ">", "<" which can't be part of attribute values). So either you encode the data (either in some completely mangled form or using SGML entities) in attribute values or you have to use CDATA.
    I'm trying to solve the problem encoding special chars that can have troubles:
    • ; -> [MY_SEMICOLON]
    • " -> [MY_QUOTE]
    • & -> [MY_AMPERSEND]
    • > -> [MY_MORETHAN]
    • < -> [MY_LESSTHAN]


    I hope this is enough
    the_bis

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

    Default Re: Problem in XML parsing ";" (semicolon) char

    It'd be really easier if you changed the structure.
    And if you want to encode, I suggest this:
    & => &amp;
    " => &quot;
    > => &gt;
    < => &lt;
    ' => &apos;

    Also encode every character with ascii value greater than 127 as &xxx; where xxx is the hex value of the ascii value. If you don't, you're likely to run into problems with encoding.

    The semicolon should be fine by itself... I don't know why it doesn't work for you.

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

    Default Re: Problem in XML parsing ";" (semicolon) char

    Could you try running this application?
    Qt Code:
    1. #include <qdom.h>
    2. #include <qstring.h>
    3.  
    4.  
    5. int main(){
    6. QDomElement root = doc.createElement("root");
    7. doc.appendChild(root);
    8. QDomElement elem = doc.createElement("test");
    9. elem.setAttribute("arg", "value1;value2;value3");
    10. root.appendChild(elem);
    11. qDebug("%s", doc.toString().ascii());
    12.  
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

    It works for me without problems, so if semicolons are causing you trouble, the problem is within your code and not Qt.

  8. The following user says thank you to wysota for this useful post:

    the_bis (1st June 2007)

  9. #8
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem in XML parsing ";" (semicolon) char

    Quote Originally Posted by wysota View Post
    Could you try running this application?
    Yes, it works also for me!

    Sorry sorry sorry: the error was in another place of my source code...

    Thank you again for your help and to let me to understand that also my XML code was right,
    the_bis

Similar Threads

  1. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 20:49

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.