dom 操作XML 的问题 $root = $dom->documentElement;$items = $root->childNodes; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 TO LS:我想取的是items下的a结点的value,不用getelmentbytagname,请问还有什么方法?类似asp的childnode(0).nodevalue这种,谢谢LS了~ 有啊,一样用 $node->childNodes->item(0)->nodeValue; TOLS:我想想啊...应该是 $root->childNodes $items(0)->childNodes->item(0)->nodeValue;请问是这样么? TOLS:xpath我也试过,还是只能取到item这级别,后面的不用tagname不知道没有什么办法了...请LS能不能详细解答,谢谢 问题在于xml的写法要是<root><item><a>11</a><b>1</b><c>0</c></item></root>如果写成<root><item><a>11</a><b>1</b><c>0</c></item></root>是完全不同的DOM结构,回车符号都算作是Node的如果是第一种写法$dom = new DOMDocument();$dom->load('result.xml');$root = $dom->documentElement;$items = $root->childNodes;$item = $items->item(0);$itemChildren = $item->childNodes;$b = $itemChildren->item(1);echo $b->nodeValue; TOLS:晕...真不知道这两种XML还有区别啊....谢谢LZ了....我回去试试....长见识了,谢谢.那第二种改怎么写呢? 请问有高手知道第二种XML怎么读么?不用TAGNAME。。谢谢了阿第一种hookee兄帮我解决了希望有高手解答谢谢 php5的话,用simplexml_load_file,很方便. 第二种就调整Item的索引数呀。$item = $items->item(1); TOLS:貌似直接这样子不行..反正我这里报错说nodeelement没有item方法...如果LS设置正确请告诉我方法... //method 1$dom = new DOMDocument();$dom->load("result.xml");$xmlPath = new DOMXPath($dom);echo $xmlPath->query('/root/item/a')->item(0)->textContent;//method 2$xml = simplexml_load_file("result.xml");print_r($xml);echo $xml->item[0]->a; PHP中如何制作查询报表 php有没得 直接把字符串分割为key value形式的函数 php实现通过http方式的即时聊天功能 php连接SqlServer错误 php中sql的意思,不太明白。 为什么在不同的公司注册域名价格会有差别??? php发邮件 MySQL (4.17) 问题 CURL的数据为什么本地和SAE打印出来结果不一样总是乱码? 哪位大神知道php如何对文件进行加密与解密的方法? php如何创建多层文件夹? $_SESSION 问题
请问是这样么?
<root><item><a>11</a><b>1</b><c>0</c></item></root>如果写成
<root>
<item>
<a>11</a>
<b>1</b>
<c>0</c>
</item>
</root>
是完全不同的DOM结构,回车符号都算作是Node的如果是第一种写法
$dom = new DOMDocument();
$dom->load('result.xml');
$root = $dom->documentElement;
$items = $root->childNodes;
$item = $items->item(0);
$itemChildren = $item->childNodes;
$b = $itemChildren->item(1);
echo $b->nodeValue;
那第二种改怎么写呢?
$dom = new DOMDocument();
$dom->load("result.xml");
$xmlPath = new DOMXPath($dom);
echo $xmlPath->query('/root/item/a')->item(0)->textContent;
//method 2
$xml = simplexml_load_file("result.xml");
print_r($xml);
echo $xml->item[0]->a;