How to add a DOCTYPE in an XML filek with DOMDocument

AitorEGAitorEG Member Posts: 342
iHi everyone?
How can i add this line to an XML file, using DOMDocument methods?

For adding this
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>

I use:

XMLDomInst:= XMLDocOut.createProcessingInstruction('xml','version="1.0" encoding="iso-8859-1" standalone="no"');

Which method could be used for adding the DOCTYPE?

Thank you very much!!


  • Options
    AitorEGAitorEG Member Posts: 342
    NavNab wrote: »

    Thanks for your answer. i was using that, in this way:
    docTypeXMlNode := XMLDocOut.CreateDocumentType(ESHIPPER SYSTEM 'https://iconnection.tnt.com/ShipperDTD2.0/EshipperIN2.dtd');
    where XMLDocOut is a DOMDocument. May be that is why it shows me he error that CreateDocumentType method doesn't exist. It is a "'Microsoft XML, v6.0'.DOMDocument" instead of a properly said XMLDocument. Any clues for this type of object?

  • Options
    AitorEGAitorEG Member Posts: 342
    These are the method that can be used on this objet:


    No hints about adding the DOCTYPE???
  • Options
    NavNabNavNab Member Posts: 181
    Hello @AitorEG

    Check here. It says
    The DocumentType node must also be inserted before the root element of the XmlDocument (if the document already has a root element, you cannot add a DocumentType node).
    And that's what was suggested in the first link:
    var xDocument = new XDocument(
      new XDocumentType(
        "-//W3C//DTD SMIL 2.0//EN",
      new XElement("Root") // --->Root is created after DocType

    Your code should do something like this:
    doctype = XMLdoc.CreateDocumentType("book", "http://mydtd.com/book.dtd", "book.dtd", null);

    Maybe someone can better help you if you share your code ?
  • Options
    AitorEGAitorEG Member Posts: 342
    Hi @NavNab

    This is my code:
    XMLDomInst:= XMLDocOut.createProcessingInstruction('xml','version="1.0" encoding="iso-8859-1" standalone="no"');
    docTypeXMlNode := XMLDocOut.createDocType('ESHIPPER' ,null, 'https://XXXXXXXXXX/EYYYYY.dtd');
    EshiperXMlNode := XMLDocOut.createNode(1,'ESHIPPER','');

    It looks like finally don't need to insert the doctype declaration, but I have to confirm that with the system owner later this morning. But anyway, it seems that the differences betwen XMLDocument and DOMDocument will create me a few more problem with the comunication, and when using http requests...

    Thank you again, really appreciate!!!
Sign In or Register to comment.