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. QDomDocument and QPath
Qt 6.11 is out! See what's new in the release blog

QDomDocument and QPath

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 616 Views 2 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.
  • D Offline
    D Offline
    Daniel Williams
    wrote on last edited by
    #1

    Is there a way to specify a qpath expression to search a QDomDocument object for a node?

    For example, I have some xml like the following:

    <config>
      <section1>
        <subsection1>
          <camera name="mycam">
             <ip>1.2.3.4</ip>
          </camera>
        </subsection1>
      </section1>
    </config>
    

    I would like to pass in an xpath like /section1/subsection1/camera[@name="mycam"] and have it return the node which I can update.

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

      Hi
      You can maybe use
      https://doc.qt.io/qt-5/qxmlquery.html

      Is QPath = XPath or did i miss something ?

      D 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        You can maybe use
        https://doc.qt.io/qt-5/qxmlquery.html

        Is QPath = XPath or did i miss something ?

        D Offline
        D Offline
        Daniel Williams
        wrote on last edited by
        #3

        @mrjj Yeah, I meant XPath. We have so many acronyms ;)

        1 Reply Last reply
        0
        • D Daniel Williams

          Is there a way to specify a qpath expression to search a QDomDocument object for a node?

          For example, I have some xml like the following:

          <config>
            <section1>
              <subsection1>
                <camera name="mycam">
                   <ip>1.2.3.4</ip>
                </camera>
              </subsection1>
            </section1>
          </config>
          

          I would like to pass in an xpath like /section1/subsection1/camera[@name="mycam"] and have it return the node which I can update.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @Daniel-Williams
          From what I can see, it's not like in e.g. MS stuff, you have to some work. See the code in https://stackoverflow.com/questions/56062025/search-for-nodes-in-a-qdomdocument-using-xpath. It's only 5 months ago, so I assume the answer is "current & correct". https://stackoverflow.com/questions/1286842/how-do-i-run-xpath-queries-in-qt looks like more work.

          As @mrjj said, there's also https://doc.qt.io/qt-5/qxmlquery.html#details, which works with XPath but not with QDomDocument, I think.

          1 Reply Last reply
          2

          • Login

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