4

The API integration documents specify that that all node name are case sensitive. I'm using PHP SimpleXMLElement and I don't see a way to force upper case node names. Has someone run across a way to force node names to upper case?

 $xmlstr = '<Request>'.
        '</Request>';


$sxe = new SimpleXMLElement($xmlstr);
$authentication = $sxe->addChild('Authentication');
$authentication->addChild('Version', '2.0');
$processid = $sxe->addChild('Process ID=importSale');
$importsale = $processid->addChild('importSale');
$importsale->addChild('SCRIPTCODE', '<![CDATA[SCRIPT001]]>');
$importsale->addChild('PRODID','<!CDATA[DNTMAN]]>');
echo $sxe->asXML();

When viewing this in “View Source” both “SCRIPTCODE” and “PRODID” are in lower case. How do I force these to upper case?

hakre
  • 193,403
  • 52
  • 435
  • 836

2 Answers2

1

In theory the code you provided does the job already! all children added to a simpleXMLElement will preserve its original case by default!

$sxe = new SimpleXMLElement('<Request></Request>');
$authentication = $sxe->addChild('Authentication');
$authentication->addChild('Version', '2.0');
$processid = $sxe->addChild('Process ID=importSale');
$importsale = $processid->addChild('importSale');
$importsale->addChild('SCRIPTCODE', '<![CDATA[SCRIPT001]]>');
$importsale->addChild('PRODID','<!CDATA[DNTMAN]]>');
echo $sxe->asXML();

What you get executing the code is something like that :

<Request>
    <Authentication>
        <Version>2.0</Version>
    </Authentication>
    <Process>
        <Process ID=importSale>
            <SCRIPTCODE><![CDATA[SCRIPT001]]></SCRIPTCODE>
            <PRODID><!CDATA[DNTMAN]]></PRODID>
        </importSale>
    </Process>
</Request>

SCRIPTCODE and PRODID both remained uppercase!

Notice : this is not the propper way to add cdata to your node values... this will lead to html-entity conversion like &lt;!CDATA[]]&gt;

ivoputzer
  • 6,427
  • 1
  • 25
  • 43
-1

Instead of viewing the source code, try echoing the output to the screen with:

echo htmlentities($sxe->asXML());
Bill Martin
  • 446
  • 2
  • 12