Jump to content

Creating XML with php


andywilliams99

Recommended Posts

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>

 

 

Link to comment
https://forums.phpfreaks.com/topic/176668-creating-xml-with-php/
Share on other sites

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>

 

 

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;

 

?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.