Question

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();
Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top