[英]How to get the element (tags) name from XML?
$xml = simplexml_load_file($URL);
foreach($xml->children() as $child)
{
foreach($child as $child)
{
$list[] = $child->getName();
}
}
<channel>
<title></title>
<link></link>
<description></description>
<item>
<title></title>
<link></link>
<description></description>
<pubDate></pubDate>
<guid isPermaLink="false"></guid>
<dc:date></dc:date>
<dc:maxQuantity></dc:maxQuantity>
</item>
<channel>
我得到了像这样的标题,链接,描述,pubDate,guid的答案
我没有
dc:date,dc:maxQuantity。,
如何获得这种类型的元素?请有人帮我。
您没有为dc:元素提供任何名称空间,但它可能与此处描述的内容非常相似
使用php的DOMDocument。
$objDOM = new DOMDocument();
$objDOM->load("test.xml"); //make sure path is correct
$note = $objDOM->getElementsByTagName("lon");
// for each note tag, parse the document and get values for
// tasks and details tag.
foreach( $note as $value )
{
$tasks = $value->getElementsByTagName("id");
$task = $tasks->item(0)->nodeValue;
$details = $value->getElementsByTagName("name");
$detail = $details->item(0)->nodeValue;
$notes = $value->getElementsByTagName("notes");
$notes = $notes->item(0)->nodeValue;
echo "$task :: $detail :: $notes <br>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.