Why, when I send XML to PHP, these are lowercase nodes, but when I parse them into PHP they are uppercase?

This is the next question to this question:

How to process XML with PHP that was sent to the server as text / xml?

JavaScript / jQuery:

var xmlDoc = jQuery.createXMLDocument( "<items></items>" ); jQuery( "items", xmlDoc ).append( jQuery( "<item>My item!</item>" ) ); jQuery.ajax({ url: "test.php", type: "POST", processData: false, contentType: "text/xml", data: xmlDoc, success: function( data ) { alert( data ); } }); 

PHP:

 $xml_text = file_get_contents("php://input"); $xml = simplexml_load_string($xml_text); echo $xml->ITEM; 

For this to work, I have to use $ xml-> ITEM. If I use the $ xml-> element, it will not work. I was wondering why, when a node element is added, it is lowercase, but when I extract it, it should now be uppercase? I would like this to be lowercase in my PHP. Thanks.

0
source share
1 answer

Your PHP script accepts <items> <ITEM> My item! </ITEM> </items> as an input. Try

 <?php $xml_text = file_get_contents("php://input"); file_put_contents('test.log.txt', $xml_text); 
if you think that is not the case.

xmlDoc is an XML document, but the jQuery result ("<item> My item! </item>") is not. Along the way, jQuery uses .nodeName, which behaves like .tagName for elements.
https://developer.mozilla.org/en/DOM/element.tagName says:

In XML (and in XML languages ​​such as XHTML), tagName is case-sensitive. In HTML, tagName returns the element name in canonical uppercase form . The tagName value matches the name nodeName.
+4
source

All Articles