andywilliams99 Posted October 6, 2009 Share Posted October 6, 2009 I need to creat an XML with php and have successfully produced a valid output. The problem I have is that the XML requirements of the application that will import the XML requires that the XML file includes the line: "<OpenShipments xmlns="x-schema:D:/Documents and Settings/VBN5CGC/My Documents/Trainings/xml autoimport WS/pruebas/OpenShipments.xdr">" How do I include this line in my output XML file??? here is what I have so far Code: $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $root = $doc->createElement('OpenShipments'); $root = $doc->appendChild($root); $occ = $doc->createElement('OpenShipment'); $occ = $root->appendChild($occ); $oc2 = $doc->createElement('ShipTo'); $oc2 = $occ->appendChild($oc2); Output: <OpenShipments> <OpenShipment> <ShipTo> </ShipTo> </OpenShipment> </OpenShipments> The requied output is: <OpenShipments xmlns="x-schema:D:/Documents and Settings/VBN5CGC/My Documents/Trainings/xml autoimport WS/pruebas/OpenShipments.xdr"> <OpenShipment> <ShipTo> </ShipTo> </OpenShipment> </OpenShipments> Quote Link to comment https://forums.phpfreaks.com/topic/176668-creating-xml-with-php/ Share on other sites More sharing options...
RichardRotterdam Posted October 6, 2009 Share Posted October 6, 2009 Hi, Use for code As for you problem check the manual for setting an attribute. domelement.setattribute Quote Link to comment https://forums.phpfreaks.com/topic/176668-creating-xml-with-php/#findComment-931404 Share on other sites More sharing options...
andywilliams99 Posted October 6, 2009 Author Share Posted October 6, 2009 thanks for the pointers. Unfortunately this didn't work: Code: $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $root = $doc->createElement('OpenShipments'); $root = $doc->appendChild($root); $root->setAttribute("xmlns", "x-schema:D:/Documents and Settings/VBN5CGC/My Documents/Trainings/xml autoimport WS/pruebas/OpenShipments.xdr"); Output: <OpenShipments> <OpenShipment> <ShipTo> Quote Link to comment https://forums.phpfreaks.com/topic/176668-creating-xml-with-php/#findComment-931420 Share on other sites More sharing options...
SchweppesAle Posted October 6, 2009 Share Posted October 6, 2009 thanks for the pointers. Unfortunately this didn't work: Code: $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $root = $doc->createElement('OpenShipments'); $root = $doc->appendChild($root); $root->setAttribute("xmlns", "x-schema:D:/Documents and Settings/VBN5CGC/My Documents/Trainings/xml autoimport WS/pruebas/OpenShipments.xdr"); Output: <OpenShipments> <OpenShipment> <ShipTo> not sure if it's this obvious. I'm still really new to XML files if it's essentially a string though... $header = '<OpenShipments xmlns="x-schema:D:/Documents and Settings/VBN5CGC/My Documents/Trainings/xml autoimport WS/pruebas/OpenShipments.xdr">'; $doc = $header.$doc; ? Quote Link to comment https://forums.phpfreaks.com/topic/176668-creating-xml-with-php/#findComment-931603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.