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. QDomNamedNodeMap, example of how to process attributes?

QDomNamedNodeMap, example of how to process attributes?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 182 Views
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I've previously written my own classes in C++ to parse XML, however today I came across the Qt classes and I would like to use these. Can anyone explain how QDomNamedNodeMap is used to work with attributes as it seems very different to other ways of working in Qt in that there are no iterators to work through the attributes in the map.

    Also the map itself looks as the name suggests as if it was designed for nodes, so how do I use it to work through all attributes and extract the name and value of each?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      I'd go with nodeName and nodeValue.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        The attributes map is returned by QDomNode::attributes.

        Then it seems that you can use a simple for loop to read through the items of the map.

        Depending on what you need, the QXmlStreamReader classes.

        Note that I haven't used these classes since some times already.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        SPlattenS 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          The attributes map is returned by QDomNode::attributes.

          Then it seems that you can use a simple for loop to read through the items of the map.

          Depending on what you need, the QXmlStreamReader classes.

          Note that I haven't used these classes since some times already.

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          @SGaist , thank you, yes I can see how to use, the contents of the class doesn't seem very relevant to attributes tho...looks as the name implies like its for nodes.

          In this example:

          QDomElement objNode = objXML.documentElement();
          
          while( !objNode.isNull() ) {
              QDomNamedNodeMap mpAttr = objNode.attributes();
              std::cout << objNode.tagName().toLatin1().data() << std::endl;
              for( int i=0; i<mpAttr.size(); i++ ) {
                  QDomNode item(mpAttr.item(i));
          

          How would I obtain the attribute name and value from the item ?

          What I'm trying to do is parse any XML file then validate it and extract all nodes with any attributes, but it seems these classes were designed specifically with the user having to know the layout of the file they are going to read and what attributes will be in the file. There doesn't seem to be a way to parse all/any attributes for a node.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            I'd go with nodeName and nodeValue.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            SPlattenS 1 Reply Last reply
            2
            • SGaistS SGaist

              I'd go with nodeName and nodeValue.

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              @SGaist , thank you, I'll take a look.

              Kind Regards,
              Sy

              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