Append QBXML declaration in XML with DOMDocument

184 views Asked by At

Trying to write clean XML for a QuickBooks integration using DOMDocument in PHP. The only thing I am stuck on is how to add the required <?qbxml version="2.0"?> after <?xml version="1.0" encoding="utf-8"?> to produce the following:

<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
.....

Here is what I have so far..

$dom = new DOMDocument('1.0', 'utf-8');
   //Need to somehow add qbxml version here
    $qbxml = $dom->appendChild($dom->createElement('QBXML'));
    $qbxmlmsg = $qbxml->appendChild($dom->createElement('QBXMLMsgsRq'));
    $qbxmlmsg->setAttribute('onError', 'stopOnError');
    $salesReceiptAddRq = $qbxmlmsg->appendChild($dom->createElement('SalesReceiptAddRq'));
    $salesReceiptAddRq->setAttribute('requestID', 1234);
$dom->formatOutput = true;
    echo $dom->saveXML();
1

There are 1 answers

0
ThW On BEST ANSWER

That node is called a processing instruction.

$dom = new DOMDocument('1.0', 'utf-8');
$dom->appendChild($dom->createProcessingInstruction('qbxml', 'version="2.0"'));
$qbxml = $dom->appendChild($dom->createElement('QBXML'));
// ...

echo $dom->saveXml();