现在我需要接受一个网络传过来的xml文件,http://bestrip.vicp.cc:352/ib_tranx_req.asp?sessionid=26dce5f1c8a338652bff7d2219dd0ffb&termid=&cmd=av&disp_special=1,这个是网络传过来的文件,$doc = new DOMDocument;
$doc->load('http://bestrip.vicp.cc:352/ib_tranx_req.asp?sessionid=26dce5f1c8a338652bff7d2219dd0ffb&termid=&cmd=av&disp_special=1');
$book = $doc->documentElement;
$airline = $book->getElementsByTagName('airline');
我这样怎么不对呢,为什么我改成了$doc->load('a.xml'); 这样就可以呢,为什么不能接受网络传过来的网址参数呢?请高手赐教……
$doc->load('http://bestrip.vicp.cc:352/ib_tranx_req.asp?sessionid=26dce5f1c8a338652bff7d2219dd0ffb&termid=&cmd=av&disp_special=1');
$book = $doc->documentElement;
$airline = $book->getElementsByTagName('airline');
我这样怎么不对呢,为什么我改成了$doc->load('a.xml'); 这样就可以呢,为什么不能接受网络传过来的网址参数呢?请高手赐教……
是本地议论,远程的应看是否打开了相应开关你可以先load()一个xml试试,应该没问题的有问题的话贴出错提示
$doc->file_get_contents('http://bestrip.vicp.cc:352/ib_tranx_req.asp?uid=wz001&sessionid=26dce5f1c8a338652bff7d2219dd0ffb&termid=&cmd=av&verify=0&start_city=SHA&arrive_city=PEK&date=2008-11-21');
$book = $doc->documentElement;
我用file_get_contents获取网络过来的也不行,到底是哪个地方出现问题了呢?
$doc->file_get_contents('http://bestrip.vicp.cc:352/ib_tranx_req.asp?uid=wz001&sessionid=26dce5f1c8a338652bff7d2219dd0ffb&termid=&cmd=av&verify=0&start_city=SHA&arrive_city=PEK&date=2008-11-21');
对了.还要加一句.编码格式自己决定
test.php
<?php
$parser = xml_parser_create(); //创建一个parser编辑器xml_set_element_handler($parser, "startElement", "endElement");//设立标签触发时的相应函数 这里分别为startElement和endElenmentxml_set_character_data_handler($parser, "characterData");//设立数据读取时的相应函数$xml_file="http://www.abc.com/1.xml";//指定所要读取的xml文件,可以是url$filehandler = fopen($xml_file, "r");//打开文件
while ($data = fread($filehandler, 4096))
{
xml_parse($parser, $data, feof($filehandler));
}//每次取出4096个字节进行处理
fclose($filehandler);
xml_parser_free($parser);//关闭和释放parser解析器$name=false;
$position=false;
function startElement($parser_instance, $element_name, $attrs) //起始标签事件的函数 {
global $name,$position;
if($element_name=="NAME")
{
$name=true;
$position=false;
echo "名字:";
}
if($element_name=="POSITION")
{$name=false;
$position=true;
echo "职位:";
}
}function characterData($parser_instance, $xml_data) //读取数据时的函数{
global $name,$position;
if($position)
echo $xml_data."<br>";
if($name)
echo $xml_data."<br>";
}function endElement($parser_instance, $element_name) //结束标签事件的函数
{
global $name,$position;
$name=false;
$position=false;
}
?>
1.xml
<?xml version="1.0" encoding="gb2312"?>
<employees>
<employee>
<name>test1</name>
<position age="45">TEST11</position>
</employee>
<employee>
<name>TEST2</name>
<position age="45">TEST22</position>
</employee>
</employees>
你的那个代码是操作XML文件的后缀名未.XML的文件的
要采用xml-rpc的方式
你构造参数向http://bestrip.vicp.cc:352/ib_tranx_req.asp发送请求,
请求时要带上后面的参数,对方收到请求按照标准,返回一个xml给你.如果你和对方是共享xml,就和对方订好协议,是要get还是post,参数怎么传之类的.
如果需要一行一行的自动分组,用file,
多看看php,多搜索:http://76xz.com/bbs/forum-5-1.html