Results 1 to 5 of 5

Thread: QtXml questions

  1. #1
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QtXml questions

    I need to realize a class for parsing configuration files with following features:

    (1): GetNodeValue(QString cnode, QString &cvaluenode, int count) const

    For example
    Qt Code:
    1. XmlParser pXmlParser;
    2.  
    3. if(!pXmlParser.OpenXml(cCmd))
    4. return false;
    5.  
    6. QString cTmp;
    7. QString cValue;
    8. QString cXml;
    9.  
    10. cXml = "node1/node2/node3"; // <- Thus I need to specify root
    11.  
    12. cTmp = cXml + "/brw"; // <- specify Node
    13. pXmlParser.GetNodeValue(cTmp, cValue); // <- get value this node
    14. m_psInfoUser.bOnBrowse = cValue == "1" ? true : false;
    To copy to clipboard, switch view to plain text mode 

    (2) GetNodeList(QString cnode, StrVector &nodes) const
    (3) GetNodeNameList(QString cnode, StrVector &nodes) const
    (4) GetAttrList(QString cnode, QString nameattr, StrVector &attr) const
    (5) GetAttrValue(QString cnode, QString nameattr, QString& valattr, int count) const

    What advise to esteem, and there are some ready examples which it can is possible to take for a basis?

  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: QtXml questions

    I think you should use the DOM approach - see QDomDocument and friends. Using Patternist (available in 4.4 snapshots) is an option as well.

  3. #3
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtXml questions

    Hmm.... Now I study documents on QDomDocument. But has not found how I knowing a way to my element I can receive its value.
    For example I have structure:

    Qt Code:
    1. <?xml version="1.0" encoding="windows-1251"?>
    2. <root>
    3. <client>
    4. <prof>
    5. <brw>1</brw>
    6. <srch>1</srch>
    7. <reg>1</reg>
    8. <edm>1</edm>
    9. <edd>1</edd>
    10. <mgn>1</mgn>
    11. </prof>
    12. </client>
    13. </root>
    To copy to clipboard, switch view to plain text mode 

    I can directly on a way of an element take value or me will have to bypass all elements searching the for the ?

  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: QtXml questions

    Qt Code:
    1. doc.setContent(...);
    2. //...
    3. QDomElement root = doc.documentElement();
    4. QDomElement srch = root.firstChildElement("client").firstChildElement("prof").firstChildElement("srch");
    5. QString s = srch.text(); // s=="1"
    To copy to clipboard, switch view to plain text mode 

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

    nico.23 (24th May 2009)

  6. #5
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtXml questions

    Quote Originally Posted by wysota View Post
    Qt Code:
    1. doc.setContent(...);
    2. //...
    3. QDomElement root = doc.documentElement();
    4. QDomElement srch = root.firstChildElement("client").firstChildElement("prof").firstChildElement("srch");
    5. QString s = srch.text(); // s=="1"
    To copy to clipboard, switch view to plain text mode 
    Thx Wysota !!!
    my code:
    Qt Code:
    1. bool XmlParser::GetNodeValue(QString cnode, QString &cvaluenode, qint16 count)
    2. {
    3. QStringList listNodes = cnode.split("/");
    4.  
    5. QDomElement root = doc->documentElement();
    6. QDomElement srch = root.firstChildElement(listNodes.at(1));
    7.  
    8. for (qint8 i = 2; i < listNodes.size(); i++)
    9. {
    10. srch = srch.firstChildElement(listNodes.at(i));
    11. }
    12.  
    13. cvaluenode = srch.text();
    14.  
    15. return true;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ...
    2. cXml = "root/client/prof";
    3.  
    4. cTmp = cXml + "/brw";
    5. pXmlParser.GetNodeValue(cTmp, cValue);
    6. m_psInfoUser.bOnBrowse = cValue == "1" ? true : false;
    7. ...
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QT "Remoting" and D-Bus questions
    By QPlace in forum General Discussion
    Replies: 3
    Last Post: 6th January 2008, 23:30
  2. MacOS QtXml prebinding?
    By skaiser in forum Installation and Deployment
    Replies: 0
    Last Post: 6th July 2007, 19:25
  3. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  4. 2 Questions about layouts
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2006, 13:54
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.