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. Getting the first line of xml file using QDom

Getting the first line of xml file using QDom

Scheduled Pinned Locked Moved Solved General and Desktop
xml parsing
7 Posts 3 Posters 2.5k 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.
  • T Offline
    T Offline
    tarod.net
    wrote on 15 Apr 2015, 12:21 last edited by A Former User
    #1

    Hello there!

    I'm trying to parse an xml file using QDomDocument and related classes, but I cannot get the first line of this file.

    Usually every xml file has as a first line like the following one:

    <?xml version="1.0" encoding="UTF-8"?>
    

    And the problem is I cannot read that line.

    Any idea? Is it possible or the first node returned by QDomDocument is always after that header?

    "Individually, we are one drop. Together, we are an ocean."

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 15 Apr 2015, 13:04 last edited by
      #2

      Disclaimer: Never used QDom.
      Normally , an xml paser will return the root object
      which is the first node/element in the document AFTER the "header"

      QDomElement QDomDocument::documentElement() const
      Returns the root element of the document.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tarod.net
        wrote on 16 Apr 2015, 06:24 last edited by tarod.net
        #3

        OK, thanks.

        I think we should have a method to get also that tag of xml files :-?

        "Individually, we are one drop. Together, we are an ocean."

        P 1 Reply Last reply 16 Apr 2015, 06:46
        0
        • T tarod.net
          16 Apr 2015, 06:24

          OK, thanks.

          I think we should have a method to get also that tag of xml files :-?

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 16 Apr 2015, 06:46 last edited by
          #4

          @tarod.net I guess there's no way to do so using QDomDocument. Strange that it has adding functionality using createProcessingInstruction but no reading.
          You can use QXmlStreamReader instead. It has documentEncoding and documentVersion methods.

          157

          T 1 Reply Last reply 16 Apr 2015, 10:50
          0
          • P p3c0
            16 Apr 2015, 06:46

            @tarod.net I guess there's no way to do so using QDomDocument. Strange that it has adding functionality using createProcessingInstruction but no reading.
            You can use QXmlStreamReader instead. It has documentEncoding and documentVersion methods.

            T Offline
            T Offline
            tarod.net
            wrote on 16 Apr 2015, 10:50 last edited by
            #5

            @p3c0 Thank you. I've been working with QXmlStreamReade. I can read the tag I mentioned in my first message using those methods :)

            "Individually, we are one drop. Together, we are an ocean."

            P 1 Reply Last reply 16 Apr 2015, 11:04
            0
            • T tarod.net
              16 Apr 2015, 10:50

              @p3c0 Thank you. I've been working with QXmlStreamReade. I can read the tag I mentioned in my first message using those methods :)

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 16 Apr 2015, 11:04 last edited by
              #6

              @tarod.net You're Welcome :) Please mark the post as solved.
              Happy Coding..

              157

              T 1 Reply Last reply 16 Apr 2015, 12:06
              0
              • P p3c0
                16 Apr 2015, 11:04

                @tarod.net You're Welcome :) Please mark the post as solved.
                Happy Coding..

                T Offline
                T Offline
                tarod.net
                wrote on 16 Apr 2015, 12:06 last edited by
                #7

                @p3c0 The same to you ;)

                "Individually, we are one drop. Together, we are an ocean."

                1 Reply Last reply
                0

                1/7

                15 Apr 2015, 12:21

                • Login

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