Php XML原子到SimpleXML对象丢失数据
嗨,我有一个简单的问题。当我尝试将atom XML字符串转换为simplexml对象或使用simplexml_load_data函数时,它似乎会删除许多属性数据 就像我原来的弦一样Php XML原子到SimpleXML对象丢失数据,php,xml,simplexml,atom-feed,Php,Xml,Simplexml,Atom Feed,嗨,我有一个简单的问题。当我尝试将atom XML字符串转换为simplexml对象或使用simplexml_load_data函数时,它似乎会删除许多属性数据 就像我原来的弦一样 <?xml version="1.0" encoding="UTF-8"?> <feed gd:kind="customsearch#search" xmlns="http://www.w3.org/2005/Atom" xmlns:cse="http://schemas.google.com/cs
<?xml version="1.0" encoding="UTF-8"?>
<feed gd:kind="customsearch#search" xmlns="http://www.w3.org/2005/Atom" xmlns:cse="http://schemas.google.com/cseapi/2010" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<title>Google Custom Search - flower</title>
<id>tag:www.googleapis.com,2010-09-29:/customsearch/v1?q=flower&&num=10&start=1&safe=off</id>
<author>
<name>- Google Custom Search</name>
</author>
<updated>1970-01-16T10:55:22.093Z</updated>
<opensearch:Url type="application/atom+xml" template="https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={cse:safe?}&cx={cse:cx?}&cref={cse:cref?}&sort={cse:sort?}&filter={cse:filter?}&gl={cse:gl?}&cr={cse:cr?}}&googlehost={cse:googleHost?}&c2coff={?cse:disableCnTwTranslation}&hq={cse:hq?}&hl={cse:hl?}&siteSearch={cse:siteSearch?}&siteSearchFilter={cse:siteSearchFilter?}&exactTerms={cse:exactTerms?}&excludeTerms={cse:excludeTerms?}&linkSite={cse:linkSite?}&orTerms={cse:orTerms?}&relatedSite={cse:relatedSite?}&dateRestrict={cse:dateRestrict?}&lowRange={cse:lowRange?}&highRange={cse:highRange?}&searchType={cse:searchType?}&fileType={cse:fileType?}&rights={cse:rights?}&imgsz={cse:imgsz?}&imgtype={cse:imgtype?}&imgc={cse:imgc?}&imgcolor={cse:imgcolor?}&alt=atom"/>
<opensearch:Query role="request" title="Google Custom Search - flower" totalResults="98800000" searchTerms="flower" count="10" startIndex="1" inputEncoding="utf8" outputEncoding="utf8" cse:safe="off" cse:cx="g"/>
<opensearch:Query role="cse:nextPage" title="Google Custom Search - flower" totalResults="98800000" searchTerms="flower" count="10" startIndex="11" inputEncoding="utf8" outputEncoding="utf8" cse:safe="off" cse:cx="0vv1rbg"/>
<opensearch:totalResults>98800000</opensearch:totalResults>
<opensearch:startIndex>1</opensearch:startIndex>
我的输出如下。所有关键信息,如搜索次数、总结果集都消失了
SimpleXMLElement Object
(
[title] => Google Custom Search - flower
[id] => tag:www.googleapis.com,2010-09-29:/customsearch/v1?q=flower&cx=&num=10&start=1&safe=off
[author] => SimpleXMLElement Object
(
[name] => Search Engine - Google Custom Search
)
[updated] => 1970-01-16T10:55:22.093Z
[entry] => Array
(
[0] => SimpleXMLElement Object
(
[id] => http://en.wikipedia.org/wiki/Flower
[updated] => 1970-01-16T10:55:22.093Z
[title] => <b>Flower</b> - Wikipedia, the free encyclopedia
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[href] => http://en.wikipedia.org/wiki/Flower
[title] => en.wikipedia.org
)
)
[summary] => A <b>flower</b>, sometimes known as a bloom or blossom, is the reproductive structure <br> found in <b>flowering</b> plants (plants of the division Magnoliophyta, also called <b>...</b>
)
simplexmlement对象
(
[标题]=>谷歌自定义搜索-花卉
[id]=>tag:www.googleapis.com,2010-09-29:/customsearch/v1?q=flower&cx=&num=10&start=1&safe=off
[作者]=>SimpleXMLElement对象
(
[名称]=>搜索引擎-谷歌自定义搜索
)
[更新]=>1970-01-16T10:55:22.093Z
[输入]=>数组
(
[0]=>SimpleXMLElement对象
(
[id]=>http://en.wikipedia.org/wiki/Flower
[更新]=>1970-01-16T10:55:22.093Z
[标题]=>花卉-维基百科,免费百科全书
[链接]=>SimpleXMLElement对象
(
[@attributes]=>数组
(
[href]=>http://en.wikipedia.org/wiki/Flower
[标题]=>en.wikipedia.org
)
)
[摘要]=>一朵花,有时被称为开花或开花,是开花植物(木兰属植物,也称为。。。
)
这些元素没有消失,您只是无法在标准转储中“看到”它们,因为它们位于不同的命名空间中。您仍然可以像这样对它们进行迭代:
foreach ($xml->children('opensearch', TRUE) as $element) {
echo $element->getName(), "\n";
}
其中,'opensearch'
表示名称空间前缀,TRUE
表示您使用了文档特定的前缀,而不是完整的名称空间url
foreach ($xml->children('opensearch', TRUE) as $element) {
echo $element->getName(), "\n";
}