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. Reading an XML document
Forum Updated to NodeBB v4.3 + New Features

Reading an XML document

Scheduled Pinned Locked Moved General and Desktop
16 Posts 8 Posters 13.8k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #7

    I prefer hexdump with switch -C to show the output - I like hex numbers more than octal/decimal values. It's available on Macs by default.

    try

    @
    hexdump -C x.xml
    00000000 ff fe 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d |..<?xml version=|
    @

    If the file is long you can use the following to just print the first line:

    @
    head -1 yourfile.xml | hexdump -C
    @

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #8

      Volker: I need to nitpick, sorry...

      Your hexdump seems to be utf-8 encoded, but "ff fe" is the UTF-16 encoded BOM (actually "ff fe" or "fe ff", depending on byte order).

      In UTF-8 the proper encoding should be: "ef bb bf" (or in ISO-8859-1 the sequence of these characters: ). Note that a Byte Order Mark does not really makes sense in a bytewise encoding... so its use is actually discouraged in a utf-8 context. BOM in UTF-8 does break e.g. scripts on Unix systems which require the shebang to be first in a file.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #9

        Tobias, you're completely right and very welcome :-)
        I better should have stated, that this is sample output of hexdump, not of valid utf-16. I must construct this stuff by hand, as none of my editors creates utf-16 with BOM :-/

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cazador7907
          wrote on last edited by
          #10

          I think that I've almost solved this problem. The issue was not BOM but that the dang fool program cant' seem to find the file to open it! I admit it. I am a dolt sometimes.

          My question for the group though is how to I specify the relative path to the file? If I specify just the filename (with not path), it can't find it. The file is co-located with the rest of the source code so I would expect it to immediately locate the file. In the project explorer though, it appears under the "Other Files" node of the tree view. I suppose that I could hard code a file path but that would defeat the purpose of relative paths.

          Source code is below.

          @
          Graph newGraph;
          QString filename;
          QFile file;

          filename = "GraphData.xml";
          
          file.setFileName(filename);
          bool results = file.open(QIODevice::ReadOnly);
          
          if(!results)
              qDebug() << file.errorString();
          else
          {
              Doing lots of good things .....
          

          @

          Laurence -

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #11

            one way is to include your xml file in a resource file

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #12

              if you locate the file somewhere in the filesystem, you need a path. If you don't specify a path, the program normally looks in the current folder (from which the executable is started). I donÄ't know, whether that is your project folder.
              MSVS uses the project folder as current directory.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #13

                If the file contents is static, you can add it to your application resources and use it in a QFile there:

                @
                QFile f(":/GraphData.xml");
                @

                See the docs on the "resource system":http://doc.qt.nokia.com/latest/resources.html for further details.

                You can manage them nicely with Qt Creator too, then there is no need to fiddle around in the qrc XML file manually.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  perego
                  wrote on last edited by
                  #14

                  Gostaria de saber se alguem consegue me explicar como eu faço pra baixar ou melhor salvar um arquivo xml via qhttp ou qurl etc

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #15

                    [quote author="perego" date="1306948065"]Gostaria de saber se alguem consegue me explicar como eu faço pra baixar ou melhor salvar um arquivo xml via qhttp ou qurl etc[/quote]

                    Please answer in English in this forum.

                    If you want to write in native language, please have a look at the respective forums.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mgran
                      wrote on last edited by
                      #16

                      [quote author="perego" date="1306948065"]Gostaria de saber se alguem consegue me explicar como eu faço pra baixar ou melhor salvar um arquivo xml via qhttp ou qurl etc[/quote]

                      "I wonder if someone can explain me how can i download or better to save a file via xml or qhttp qurl etc."

                      (from Google Translate)

                      Project Manager - Qt Development Frameworks

                      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