这是此答案的后续问题:
How do I parse XML from 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;
为了使其工作,我必须使用 $xml->ITEM。如果我使用 $xml->item 它将不起作用。我想知道为什么当项目节点被附加时它是小写的,但是当我检索它时,它现在必须是大写的?我希望它在我的 PHP 中是小写的。谢谢。
最佳答案
您的 PHP 脚本接收
<?php
$xml_text = file_get_contents("php://input");
file_put_contents('test.log.txt', $xml_text);
如果你认为事实并非如此。
xmlDoc 是一个 xml 文档,但 jQuery( "
https://developer.mozilla.org/en/DOM/element.tagName说:
In XML (and XML-based languages such as XHTML), tagName preserves case. In HTML, tagName returns the element name in the canonical uppercase form. The value of tagName is the same as that of nodeName.
关于php - 为什么当我将 XML 发送到 PHP 时,节点是小写的,但当我在 PHP 中解析它们时,它们是大写的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/949942/