2012-04-25 3 views
0

안녕하세요, 간단한 문제가 있습니다. 내가 개체 또는 simplexml_load_data 기능을 사용하여 SimpleXML을 할 수있는 원자 XML 문자열로 변환 할 때, 많은 속성 데이터를 삭제할 것 같다 ... 내 원래의 문자열에서 같은XML ATOM에서 SimpleXML로 데이터 손실 데이터

내가로 변환 할 때 내가

<?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&amp;&amp;num=10&amp;start=1&amp;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}&amp;num={count?}&amp;start={startIndex?}&amp;lr={language?}&amp;safe={cse:safe?}&amp;cx={cse:cx?}&amp;cref={cse:cref?}&amp;sort={cse:sort?}&amp;filter={cse:filter?}&amp;gl={cse:gl?}&amp;cr={cse:cr?}}&amp;googlehost={cse:googleHost?}&amp;c2coff={?cse:disableCnTwTranslation}&amp;hq={cse:hq?}&amp;hl={cse:hl?}&amp;siteSearch={cse:siteSearch?}&amp;siteSearchFilter={cse:siteSearchFilter?}&amp;exactTerms={cse:exactTerms?}&amp;excludeTerms={cse:excludeTerms?}&amp;linkSite={cse:linkSite?}&amp;orTerms={cse:orTerms?}&amp;relatedSite={cse:relatedSite?}&amp;dateRestrict={cse:dateRestrict?}&amp;lowRange={cse:lowRange?}&amp;highRange={cse:highRange?}&amp;searchType={cse:searchType?}&amp;fileType={cse:fileType?}&amp;rights={cse:rights?}&amp;imgsz={cse:imgsz?}&amp;imgtype={cse:imgtype?}&amp;imgc={cse:imgc?}&amp;imgcolor={cse:imgcolor?}&amp;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> 

을 가지고 있지만 xml을 사용하여

내 출력은 아래와 같습니다. 그들은 다른 네임 스페이스에 있기 때문에 이러한 요소가 사라되지 않습니다

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> 
       ) 

답변

1

검색 수, 사라 설정 전체 결과와 같은 모든 주요 정보는 ..., 당신은 단지, 표준 덤프를 "볼"수 없습니다 . 당신은 여전히이처럼 반복 할 수 있습니다 'opensearch' 네임 스페이스 접두사를 표시하고 TRUE

foreach ($xml->children('opensearch', TRUE) as $element) { 
    echo $element->getName(), "\n"; 
} 

이 문서 특정 접두사 대신 풀 네임 스페이스 URL을 사용하는 것을 의미한다.