如何提取< uri>< / uri>的内容在XML文档中? [英] How to extract the content of <uri></uri> in a XML document?
本文介绍了如何提取< uri>< / uri>的内容在XML文档中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,它的结构如下所示。
有很多< entry>
。我的问题是如何输出每个条目的< uri>
?另一个问题是,如何只输出 USERNAME
?
I have a document that it's structure is like below.
There are a lot of <entry>
. My question is how can I output the <uri>
of each entry? And another question, how can I output only the USERNAME
?
这是我要获取用户名的文件 http://search.twitter.com/search.atom?q=yankees
This is the file I want to get the usernames http://search.twitter.com/search.atom?q=yankees
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/" xmlns:georss="http://www.georss.org/georss">
<entry>
<author>
<name></name>
<uri>http://twitter.com/USERNAME</uri>
</author>
</entry>
推荐答案
<?php
$xml = new DOMDocument;
// link to ur file
$xml->load('');
foreach ($xml->getElementsByTagName('entry') as $product )
{
$append = array();
foreach($product->getElementsByTagName('uri') as $name ) {
// Stick $name onto the array
$append[] = $name;
}
}
$result = $xml->saveXML();
print_r(str_replace('http://twitter.com/','',$result));
?>
这篇关于如何提取< uri>< / uri>的内容在XML文档中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文