Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Access XML nodes
Forum Updated to NodeBB v4.3 + New Features

Access XML nodes

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 348 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    russjohn834
    wrote on last edited by russjohn834
    #1

    Hi all,

    I have an XML of following structure:

    <?xml version="1.0"?>
    <subject_details>
     <Name>Name2</Name>
     <Surname>Surname2</Surname>
     <Patient_ID>PID02</Patient_ID>
     <Date>01/01/2000 00:00</Date>
     <Clinician_Note>note </Clinician_Note>
     <Settings>
      <Current>12</Current>
      <PW>120</PW>
      <Freq>30</Freq>
     </Settings>
    </subject_details>
    

    I'm using QDomDocument to read.
    I can get individual node value by tagname, for ex:

    root.elementsByTagName("Current").at(0).firstChild().nodeValue();
    

    This gives me the Current node value 12

    What's the method to get all node values under Settings node?

    Thank you

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Often by simply enumerating the elements

      QDomNode n = docElem.firstChild();
      while(!n.isNull()) {
          QDomElement e = n.toElement(); // try to convert the node to an element.
          if(!e.isNull()) {
              cout << qPrintable(e.tagName()) << endl; // the node really is an element.
          }
          n = n.nextSibling();
      }
      

      https://doc.qt.io/qt-5/qdomdocument.html

      1 Reply Last reply
      4
      • R russjohn834

        Hi all,

        I have an XML of following structure:

        <?xml version="1.0"?>
        <subject_details>
         <Name>Name2</Name>
         <Surname>Surname2</Surname>
         <Patient_ID>PID02</Patient_ID>
         <Date>01/01/2000 00:00</Date>
         <Clinician_Note>note </Clinician_Note>
         <Settings>
          <Current>12</Current>
          <PW>120</PW>
          <Freq>30</Freq>
         </Settings>
        </subject_details>
        

        I'm using QDomDocument to read.
        I can get individual node value by tagname, for ex:

        root.elementsByTagName("Current").at(0).firstChild().nodeValue();
        

        This gives me the Current node value 12

        What's the method to get all node values under Settings node?

        Thank you

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @russjohn834
        As @mrjj has said, QDomDocument basically wants you to walk the tree as necessary to visit things.

        There is https://doc.qt.io/qt-5/qdomnode.html#childNodes to give you the list of children in one go instead of calling firstChild()/nextSibling() etc. But you'll still have to iterate through them if you want to see what's inside. You won't find a single "get all node values under node".

        1 Reply Last reply
        5
        • R Offline
          R Offline
          russjohn834
          wrote on last edited by
          #4

          Thank you @mrjj , @JonB

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved