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. Question about XML header
Forum Updated to NodeBB v4.3 + New Features

Question about XML header

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.0k 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.
  • X Offline
    X Offline
    xtingray
    wrote on 18 Feb 2016, 15:58 last edited by xtingray
    #1

    Hi,
    I have seen this instruction used in several projects:

    QDomDocument::createProcessingInstruction()
    

    Specifically a line like this:

    doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
    

    My question is: To include this header within an XML file add some special feature for real? If I do something like:

    QDomDocument document;
    document.setContent(xml);
    

    That header has any impact on the setContent() method behavior?

    I appreciate any hint. Thanks!


    Qt Developer

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 18 Feb 2016, 22:01 last edited by
      #2

      Those are two different use cases.

      The first snippet is usually used when you create the xml, i.e. build a document and store it. In this case you need it or the consumer of such xml will not know how to handle the file.

      The other one is when you open up an existing document, e.g. from file. It will most probably already have the version and encoding declaration in that file already. When you setContent() you effectively replace the dom tree so anything that was there before, be it a processing instruction, nodes or attributes, is gone anyway.

      So to answer your question:
      You should add it when you hand craft and store a new xml.
      When you read a file and call setContent()it does nothing as it is basically discarded with the rest of pre-existing content.

      Btw. technically version and encoding are not even processing instructions but since the syntax is the same it just works.

      1 Reply Last reply
      0

      1/2

      18 Feb 2016, 15:58

      • Login

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