php xml文件怎么取里面的值,我老是取不到
文件地址http://oss.aliyun.com/manage/object/down?bucket=myappmp3&filename=b.xml对着下面地址,我一个...
文件地址http://oss.aliyun.com/manage/object/down?bucket=myappmp3&filename=b.xml
对着下面地址,我一个都取不到
$xml = simplexml_load_file('MessagesNew.xml');
echo $xml->itemcats_get_response->item_cats['list'];
var_dump($xml->itemcats_get_response->item_cats);
取到NULL值 展开
对着下面地址,我一个都取不到
$xml = simplexml_load_file('MessagesNew.xml');
echo $xml->itemcats_get_response->item_cats['list'];
var_dump($xml->itemcats_get_response->item_cats);
取到NULL值 展开
3个回答
展开全部
php
$doc = new DOMDocument();
//先定义一个类
$doc->load( ‘books.xml’ );
//加载入你要读取的xml文件
$books = $doc->getElementsByTagName( “book” );
//查找xml中节点为book的,将整个节点赋给一个变量
foreach( $books as $book )
//循环对$books进行操作
{
$authors = $book->getElementsByTagName( “author” );
//找出book节点里面的子节点,名称为author
$author = $authors->item(0)->nodeValue;
//去到节点author里面的值
$publishers = $book->getElementsByTagName( “publisher” );
//找出book节点里面的子节点,名称为publisher
$publisher = $publishers->item(0)->nodeValue;
//找出节点publisher里面的值
$titles = $book->getElementsByTagName( “title” ); // 同上
$title = $titles->item(0)->nodeValue;
echo “$title – $author – $publisher\n”;
}
以下是books.xml文件
<book>
<author>1111</author>
<publishers>2222</publishers>
<title>33333</title>
</book>
<book>
<author>1111</author>
<publishers>2222</publishers>
<title>33333</title>
</book>
<book>
<author>1111</author>
<publishers>2222</publishers>
<title>33333</title>
</book>
$doc = new DOMDocument();
//先定义一个类
$doc->load( ‘books.xml’ );
//加载入你要读取的xml文件
$books = $doc->getElementsByTagName( “book” );
//查找xml中节点为book的,将整个节点赋给一个变量
foreach( $books as $book )
//循环对$books进行操作
{
$authors = $book->getElementsByTagName( “author” );
//找出book节点里面的子节点,名称为author
$author = $authors->item(0)->nodeValue;
//去到节点author里面的值
$publishers = $book->getElementsByTagName( “publisher” );
//找出book节点里面的子节点,名称为publisher
$publisher = $publishers->item(0)->nodeValue;
//找出节点publisher里面的值
$titles = $book->getElementsByTagName( “title” ); // 同上
$title = $titles->item(0)->nodeValue;
echo “$title – $author – $publisher\n”;
}
以下是books.xml文件
<book>
<author>1111</author>
<publishers>2222</publishers>
<title>33333</title>
</book>
<book>
<author>1111</author>
<publishers>2222</publishers>
<title>33333</title>
</book>
<book>
<author>1111</author>
<publishers>2222</publishers>
<title>33333</title>
</book>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询