Results 1 to 2 of 2

Thread: QXmlStreamReader not giving all the attributes of an element

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QXmlStreamReader not giving all the attributes of an element

    Hi,
    I'm trying to parse an xml file and when I try to read through the first element, I'm not getting all the corresponding attributes of that element. Only a few are getting noticed. Would be of great help if someone help me in finding the issue.

    My xml file is
    Qt Code:
    1. <nvd xmlns="http://scap.nist.gov/schema/feed/vulnerability/2.0" xmlns:cpe-lang="http://cpe.mitre.org/language/2.0" xmlns:vuln="http://scap.nist.gov/schema/vulnerability/0.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:scap-core="http://scap.nist.gov/schema/scap-core/0.1" xmlns:cvss="http://scap.nist.gov/schema/cvss-v2/0.2" xmlns:patch="http://scap.nist.gov/schema/patch/0.1" nvd_xml_version="2.0" xsi:schemaLocation="http://scap.nist.gov/schema/patch/0.1 http://nvd.nist.gov/schema/patch_0.1.xsd http://scap.nist.gov/schema/scap-core/0.1 http://nvd.nist.gov/schema/scap-core_0.1.xsd http://scap.nist.gov/schema/feed/vulnerability/2.0 http://nvd.nist.gov/schema/nvd-cve-feed_2.0.xsd" pub_date="2011-10-23T16:00:27">
    2. <entry id="CVE-2016-4172">
    3. <vuln:vulnerable-configuration id="http://nvd.nist.gov/">
    4. <cpe-lang:logical-test operator="AND" negate="false">
    5. <cpe-lang:logical-test operator="OR" negate="false">
    6. <cpe-lang:fact-ref name="cpe:/a:adobe:flash_player:11.2.202.626" />
    7. </cpe-lang:logical-test>
    8. <cpe-lang:logical-test operator="OR" negate="false">
    9. <cpe-lang:fact-ref name="cpe:/o:linux:linux_kernel" />
    10. </cpe-lang:logical-test>
    11. </cpe-lang:logical-test>
    12. </vuln:vulnerable-configuration>
    13. </entry>
    14. </nvd>
    To copy to clipboard, switch view to plain text mode 

    My code to to find the attributes of an element -
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QDebug>
    3. #include <QXmlStreamReader>
    4. #include <QFile>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9.  
    10. QFile file("C:/Users/shravan/Documents/rahul_prac/test.xml");
    11. if(!file.open(QFile::ReadOnly)) { qDebug() << "Cannot read file" << file.errorString(); }
    12.  
    13. QXmlStreamReader xml(&file);
    14. while(!xml.atEnd())
    15. {
    16. if(xml.isStartElement())
    17. {
    18. if(xml.name() == "nvd")
    19. {
    20. int count = xml.attributes().count();
    21. for(int i = 0; i < count; i++)
    22. {
    23. qDebug() << xml.attributes().at(i).name().toString()
    24. << ": "
    25. << xml.attributes().at(i).value().toString();
    26. qDebug() << "\n\n";
    27. }
    28. }
    29. }
    30. xml.readNextStartElement();
    31. }
    32.  
    33. return a.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    My result is
    Qt Code:
    1. "nvd_xml_version" : "2.0"
    2.  
    3. "schemaLocation" : "http://scap.nist.gov/schema/patch/0.1 http://nvd.nist.gov/schema/patch_0.1.xsd http://scap.nist.gov/schema/scap-core/0.1 http://nvd.nist.gov/schema/scap-core_0.1.xsd http://scap.nist.gov/schema/feed/vulnerability/2.0 http://nvd.nist.gov/schema/nvd-cve-feed_2.0.xsd"
    4.  
    5. "pub_date" : "2011-10-23T16:00:27"
    To copy to clipboard, switch view to plain text mode 

    There are more attributes in the xml than what I get in the result. I'm thinking what could possibly be wrong. Thanks.

    Thanks

  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: QXmlStreamReader not giving all the attributes of an element

    You have all the attributes that are not related to declaring a namespace, i.e. All the attributes with names not starting "xmlns".

    You can use namespaceDeclarations() to access the namespace information. Alternatively, you can disable namespace handling with a property of the QXmlStreamReader.

  3. The following user says thank you to ChrisW67 for this useful post:

    rawfool (19th October 2016)

Similar Threads

  1. Replies: 1
    Last Post: 30th November 2013, 11:03
  2. QWebView not changing attributes
    By januszmk in forum Newbie
    Replies: 0
    Last Post: 26th March 2013, 14:15
  3. Replies: 9
    Last Post: 23rd April 2012, 13:53
  4. XML Getting attributes of a specific value
    By di_zou in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2009, 12:04
  5. Profile Attributes
    By joy in forum Newbie
    Replies: 1
    Last Post: 8th September 2006, 16:11

Tags for this Thread

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.