DOMImplementationRegistry::getDOMImplementation on QtXML



  • Is there a direct mapping from the below implementation using Xerces on QtXML? Or for getting the DOM Implementation object I always need a QDomDocument instance?

    @
    DOMImplementation impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode((const char)"Range"));
    @

    thanks in advance!



  • There is only on DOM implementation instance, that's Qt's. So there is no need to have a registry here.

    What do you want to do with that object?



  • Actually all I need is that my XML file has to have:

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

    on the first line, even before:

    @<!DOCTYPE System PUBLIC "-//blabla/bla" "b.dtd">@

    for instance. I'm using QDomDocument::save() and the document never has what I need as a the first line so I thought that I was missing to get this implementation object from this "magical" registry that we don't have on QtXML. I'm clearly wrong about that, but how can I have this first line that I need now?

    Thanks in advance



  • As I've said in another thread about xml declaration you simply can get text representation of your xml, concat with declaration and save manually to file.



  • This works for me:

    @
    QDomDocument doc("System PUBLIC "-//blabla/bla" "b.dtd"");
    QDomProcessingInstruction pi = doc.createProcessingInstruction("xml", "version="1.0" encoding="UTF-8" standalone="no" ");
    doc.appendChild(pi);

    QDomElement root = doc.createElement("System");
    doc.appendChild(root);

    QDomElement tag = doc.createElement("Greeting");
    root.appendChild(tag);

    QDomText t = doc.createTextNode("Hello World");
    tag.appendChild(t);

    QString xml = doc.toString();
    @



  • Volker, there is one problem in your code. XML declaration looks like processing instruction, but is not a processing instruction. Declaration can be only at the beginning of the file and instruction can be anywhere in file. So in your order of commands all will work ok, but only in this order (so your second command should always be second).



  • This works in very place:

    @
    QDomProcessingInstruction pi = doc.createProcessingInstruction("xml", "version="1.0" encoding="UTF-8" standalone="no" ");
    doc.insertBefore(pi, QDomNode());
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.