How to set Exact XML element name in DomDocument with PHP

Wednesday, November 4, 2015

I have a form which on POST creates an XML based on the values in the form. I am using DOM DOCUMENT to create XML. I am giving exact element names when creating xml but when it is created the element names are in lowercase which my API is not accepting. for eg.



I am giving this as an input <LSP_Name>JaVAS</LSP_Name> and when it is created it forms like this <lsp_name>JaVAS</lsp_name>



I tried $xml->formatOutput=true; but had no luck.



Any one who had faced this similar issue ?



DOCUMENT CREATION



$xml = new DOMDocument('1.0', 'utf-8');

$xml->formatOutput=true;
$root = $xml->createElement("NewDataSet");
$xml->appendChild($root);

$LSP_Code = $xml->createElement("LSP_Code");
$LSP_CodeText = $xml->createTextNode(LSP_CODE);
$LSP_Code->appendChild($LSP_CodeText);

$docket = $xml->createElement("Docket");
$root->appendChild($docket);
$docket->appendChild($LSP_Code);


TIA

0 comments:

Post a Comment