php 解析xml问题 客户端发请求头后跟着一个xml信息,怎么才能解析呢,哪位给举个例子,谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $strXML = $_POST['xxx'];//$strXML = $_GET['xxx'];$xml = simplexml_load_string($strXML);var_dump($xml); php的手册呀.官网去下<?php$xml = new SimpleXMLElement('<person> <child role="son"> <child role="daughter"/> </child> <child role="daughter"> <child role="son"> <child role="son"/> </child> </child></person>');foreach ($xml->children() as $second_gen) { echo ' The person begot a ' . $second_gen['role']; foreach ($second_gen->children() as $third_gen) { echo ' who begot a ' . $third_gen['role'] . ';'; foreach ($third_gen->children() as $fourth_gen) { echo ' and that ' . $third_gen['role'] . ' begot a ' . $fourth_gen['role']; } }}?> 通过抓包看,客户端发来的httpheader,然后后面就是xml。像这样:POST /cm/portalapi HTTP/1.1Host: 111.140.17.43:28080Cookie: JSESSIONID=C3E17C85AED6C57B658CC7F27AE68BBD; Path=/cmreadContent-Length: 178Content-Type: application/xmlClient-Agent: s60_v3_v1r2_0030/240*320x-up-calling-line-id: 13888888888user-id: a15ba9b5458ec3e3caa8909d84113674APIVersion: 1.0.0Action: addUserBookClientHash: 0sEicJNzReY/EU8dxXpBgA==<Request><AddUserBookReq><Book><contentID>92357</contentID><chapterID>92366</chapterID><position>37</position></Book></AddUserBookReq></Request>我怎么首先获取这个xml呢, $strXML = file_get_contents("php://input"); 你没明白我的意思,我没有现成的xml文件啊就是客户端发过来,我怎么获得这个xml文件,再进行解析。就像我用$_GET['xxx']可以获得get后面的参数。现在问题是我怎么获得这个xml文件先。刚学,不太懂,麻烦了 楼上的我帖的代码就是获取XML的代码,因为你客户端POST数据,是直接POST的,没有键值,所以只能这样获取.你试试就知道了. 哈哈,你可以用 file_get_contents() 或者 curl_init() 铁公鸡的没错$strXML = file_get_contents("php://input");得到的时XML文件的内容。对$strXML进行XML解析就行了。XML解析的资料网上搜一下,一堆 php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype="multipart/form-data". [code=PHP]$doc = new DOMDocument();$doc->loadXML(‘<person> <child role="son"> <child role="daughter"/> </child> <child role="daughter"> <child role="son"> <child role="son"/> </child> </child></person>’);//loadXML($result)$CRS = $doc->documentElement; $Item = $CRS->getElementsByTagName(person);[/code] 问题是我太懂啊,$strXML=file_get_contents("php://input"); 直接输这个就能把post的信息获过来啊 自创一个网站出现的smarty问题? 如何做一个tag标签页 寻一个GD库处理动态图的方法 php的全局问题 数组中的引用是怎么回事 数据库连接查询的问题 php项目中可以放入asp.net文件吗? php(实现带省略号的分页) 同一个域下PHP有办法得到asp产生的session么? excel两个表中中文字段匹配不成功 php 连接不上MSSQL,用的tomcat加APACHE,高分在线等,谢谢 php生成贺卡,并且群发邮件功能
$strXML = $_POST['xxx'];
//$strXML = $_GET['xxx'];
$xml = simplexml_load_string($strXML);
var_dump($xml);
官网去下
<?php
$xml = new SimpleXMLElement(
'<person>
<child role="son">
<child role="daughter"/>
</child>
<child role="daughter">
<child role="son">
<child role="son"/>
</child>
</child>
</person>');foreach ($xml->children() as $second_gen) {
echo ' The person begot a ' . $second_gen['role']; foreach ($second_gen->children() as $third_gen) {
echo ' who begot a ' . $third_gen['role'] . ';'; foreach ($third_gen->children() as $fourth_gen) {
echo ' and that ' . $third_gen['role'] .
' begot a ' . $fourth_gen['role'];
}
}
}
?>
POST /cm/portalapi HTTP/1.1Host: 111.140.17.43:28080Cookie: JSESSIONID=C3E17C85AED6C57B658CC7F27AE68BBD; Path=/cmreadContent-Length: 178Content-Type: application/xmlClient-Agent: s60_v3_v1r2_0030/240*320x-up-calling-line-id: 13888888888user-id: a15ba9b5458ec3e3caa8909d84113674APIVersion: 1.0.0Action: addUserBookClientHash: 0sEicJNzReY/EU8dxXpBgA==<Request><AddUserBookReq><Book><contentID>92357</contentID><chapterID>92366</chapterID><position>37</position></Book></AddUserBookReq></Request>我怎么首先获取这个xml呢,
就是客户端发过来,我怎么获得这个xml文件,再进行解析。就像我用$_GET['xxx']可以获得get后面的参数。
现在问题是我怎么获得这个xml文件先。
刚学,不太懂,麻烦了
因为你客户端POST数据,是直接POST的,没有键值,所以只能这样获取.
你试试就知道了.
$strXML = file_get_contents("php://input");
得到的时XML文件的内容。
对$strXML进行XML解析就行了。XML解析的资料网上搜一下,一堆
php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype="multipart/form-data".
[code=PHP]
$doc = new DOMDocument();
$doc->loadXML(‘<person>
<child role="son">
<child role="daughter"/>
</child>
<child role="daughter">
<child role="son">
<child role="son"/>
</child>
</child>
</person>’);//loadXML($result)
$CRS = $doc->documentElement;
$Item = $CRS->getElementsByTagName(person);
[/code]