为什么当我将XML发送到PHP时,节点是小写的,但是当我在PHP中解析它们时,它们是大写的? [英] Why when I send XML to PHP are the nodes lowercase, but when I parse them in PHP they are uppercase?

查看:88
本文介绍了为什么当我将XML发送到PHP时,节点是小写的,但是当我在PHP中解析它们时,它们是大写的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是此答案的后续问题:

This is a follow up question to this answer:

JavaScript/jQuery:

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中是小写的.谢谢.

In order for this to work I have to use $xml->ITEM. If I use $xml->item it will not work. I was wondering why when the item node gets appended it is lowercase, but when I retrieve it, it now has to be uppercase? I would like it to be lowercase in my PHP. Thanks.

推荐答案

您的PHP脚本收到< items>< ITEM>我的商品!</ITEM></items>作为输入.如果您认为不是这样,请尝试

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

<?php
$xml_text = file_get_contents("php://input");
file_put_contents('test.log.txt', $xml_text);

.

xmlDoc是xml文档,但是jQuery(< item>我的项目!</item>")的结果不是. jQuery沿用.nodeName的行为类似于元素的.tagName.
https://developer.mozilla.org/en/DOM/element.tagName说:

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

在XML(以及基于XML的语言,例如XHTML)中,tagName保留大小写.在HTML中,tagName 以规范的大写形式返回元素名称. tagName的值与nodeName的值相同.
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.

这篇关于为什么当我将XML发送到PHP时,节点是小写的,但是当我在PHP中解析它们时,它们是大写的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆