2015-02-18 97 views
0

我在這裏嘗試了幾種不同的方法,但無濟於事。有人可以向我解釋如何解析以下類型的提要?下面是摘錄解析命名空間內的feed

<?xml version='1.0'?> 
<NoticeResults xmlns:sql="urn:schemas-microsoft-com:xml-sql"> 
<sql:query> 
    <Notice> 
     <PersonId>174171199</PersonId> 
     <NamePrefix></NamePrefix> 
     <NameAdditionalPrefix></NameAdditionalPrefix> 
     <FirstName>Donna</FirstName> 
     <MiddleName></MiddleName> 
     <LastName>Autrey</LastName> 
     <NameSuffix></NameSuffix> 
     <NameAdditionalSuffix></NameAdditionalSuffix> 
     <MaidenName></MaidenName> 
     <City></City> 
     <State>IL</State> 
     <Country>United States</Country> 
     <DateEntered>2015-02-17T00:00:00</DateEntered> 
     <DateCompleted>2015-02-17T00:00:00</DateCompleted> 
     <DateExpired>2015-03-19T00:00:00</DateExpired> 
     <NoticeText>&lt;p&gt;&lt;B&gt;PEKIN &lt;/B&gt;- Donna Lou (Morris) Autrey, 83, of Pekin passed away at 1:10 p.m. Sunday, Feb. 15, 2015, at Autumn Accolade in Green Valley.&lt;/p&gt;&lt;p&gt;A graveside service will be at 11 a.m. Thursday at Lakeside Cemetery. There will be no visitation. Preston-Hanley Funeral Homes &amp;amp; Crematory is in charge of arrangements.&lt;/p&gt; 
</NoticeText> 
     <NoticeType>Courtesy</NoticeType> 
     <Status>Active</Status> 
     <FromToYears></FromToYears> 
     <AffiliateSite>PJStar</AffiliateSite> 
     <AffiliateAdId>Autrey_02/17/2015_4673625</AffiliateAdId> 
     <PublishedBy>Peoria Journal Star</PublishedBy> 
     <DisplayURL>http://www.legacy.com/Link.asp?I=LS000174171199</DisplayURL> 
     <LocationList></LocationList> 
     <ShowInSpotlight>0</ShowInSpotlight> 
     <DateCreated>2015-02-17T01:12:37.510</DateCreated> 
     <RowVersion>793618506</RowVersion> 
     <GuestBookURL></GuestBookURL> 
    </Notice> 
    <Notice> 
     <PersonId>174171209</PersonId> 
     <NamePrefix></NamePrefix> 
     <NameAdditionalPrefix></NameAdditionalPrefix> 
     <FirstName>Lois</FirstName> 
     <MiddleName></MiddleName> 
     <LastName>Barden</LastName> 
     <NameSuffix></NameSuffix> 
     <NameAdditionalSuffix></NameAdditionalSuffix> 
     <MaidenName></MaidenName> 
     <City>Peoria</City> 
     <State>IL</State> 
     <Country>United States</Country> 
     <DateEntered>2015-02-17T00:00:00</DateEntered> 
     <DateCompleted>2015-02-17T00:00:00</DateCompleted> 
     <DateExpired>2015-03-19T00:00:00</DateExpired> 
<NoticeText>&lt;img src="/Images/Cobrands/PJStar/Photos/C7KC6NVUW02_021715.jpg" align="left" border="0" vspace="4" hspace="10" lgyOrigName="C7KC6NVUW02.jpg"&gt;&lt;p&gt;&lt;B&gt;PEORIA &lt;/B&gt;- Lois Mae Barden, age 84, of Peoria passed away Sunday, Feb. 15, 2015, at OSF Saint Francis Medical Center in Peoria.&lt;/p&gt;&lt;p&gt;Lois was born on Sept. 12, 1930, in Macomb, Ill. She married James W. Barden on June 12, 1948, in Peoria. He preceded her in death in June of 1988. &lt;/p&gt;&lt;p&gt;She also was preceded in death by her parents and 12 siblings.&lt;/p&gt;&lt;p&gt;Surviving are her children, Kathy (Ted) Kindred of Manito, Ill., Lynn (Allen) Simer of Nineveh, Ind., and Jim (Deb) Barden of North Pekin, Ill.; four grandchildren; six great-grandchildren; one great-great-grandson; and her two sisters, Doris Butts and Maggie Hoyt.&lt;/p&gt;&lt;p&gt;Lois enjoyed spending time at home with her family. She was always there to care for them when they were in need. She also enjoyed listening to Christian music, crafting, cooking and crocheting.&lt;/p&gt;&lt;p&gt;A visitation will be from 1 to 2 p.m. Thursday, Feb. 19, 2015, at Davison-Fulton Woodland Chapel in Peoria. Burial will follow at Swan Lake Memory Gardens in Peoria. &lt;/p&gt;&lt;p&gt;Memorials may be made to Illinois Cancer Care.&lt;/p&gt;&lt;p&gt;Online condolences may be made through &lt;a href="http://www.davison-fulton.com" target="_new" rel="nofollow"&gt;www.davison-fulton.com&lt;/a&gt;.&lt;/p&gt;&lt;center&gt;&lt;br&gt;&lt;a rel="nofollow" href="http://www.davison-fulton.com" target="_blank"&gt;&lt;img src="/Images/Cobrands/PJStar/Logos/www.davison-fulton.com.jpg" border="0"&gt;&lt;/a&gt;&lt;/center&gt; 
</NoticeText> 
     <NoticeType>Paid</NoticeType> 
     <Status>Active</Status> 
     <FromToYears></FromToYears> 
     <AffiliateSite>PJStar</AffiliateSite> 
     <AffiliateAdId>Barden_02/17/2015_102257420</AffiliateAdId> 
     <PublishedBy>Peoria Journal Star</PublishedBy> 
     <DisplayURL>http://www.legacy.com/Link.asp?I=LS000174171209</DisplayURL> 
     <LocationList></LocationList> 
     <FHIndex>10868</FHIndex> 
     <FHName>Davison-Fulton Woodland Chapel</FHName> 
     <FHKnownByName1>Davison-Fulton Woodland Chapel</FHKnownByName1> 
     <FHAddressLine1>2021 North University Street</FHAddressLine1> 
     <FHCity>Peoria</FHCity> 
     <FHStateProvince>IL </FHStateProvince> 
     <FHZipCode>61604  </FHZipCode> 
     <FHPhoneNumber1>3096885700  </FHPhoneNumber1> 
     <FHUrl>www.davison-fulton.com</FHUrl> 
     <ShowInSpotlight>0</ShowInSpotlight> 
     <DateCreated>2015-02-17T01:13:01.857</DateCreated> 
     <ImageUrl>http://mi-cache.legacy.com/legacy/images/Cobrands/PJStar/Photos/C7KC6NVUW02_021715.jpg</ImageUrl> 
     <RowVersion>793622447</RowVersion> 
     <GuestBookURL>http://www.legacy.com/Link.asp?I=GB000174171209</GuestBookURL> 
    </Notice> 
</sql:query> 
</NoticeResults> 

我一直在敲我的頭靠在桌子上這個整天(8小時巨大浪費)。我們在辦公室使用的所有工具都是PHP(由我們的CMS限制)。有人可以解釋我將如何去解析這樣的飼料嗎?我已經走得很遠,但似乎無法弄清楚這一點。也請解釋爲什麼你做任何事情來完成這項工作。我將不得不分析幾種以這種方式構建的提要,而我從來沒有處理過這個問題。任何幫助將不勝感激。

謝謝! Chris

+0

http://stackoverflow.com/questions/595946/parse-xml-with-namespace-using-simplexml – Ghost 2015-02-18 00:43:20

回答

1

您可以使用DOM Extension訪問元素。 w3schools有一個looping through XML的例子。

<?php 
$xmlDoc = new DOMDocument(); 
$xmlDoc->load("doc.xml"); 

$x = $xmlDoc->documentElement; 
foreach ($x->childNodes AS $item) { 
    // Do whatever is needed 
} 
?> 
+0

尼斯的答案,但是你能在你的答案提供這個例子嗎? – Victor2748 2015-02-18 00:55:15

+0

@ Victor2748鏈接到頁面是不夠的? – Peky 2015-02-18 01:00:41

+0

不可以。即使提供的鏈接完全回答了問題,如果您提供直接回答問題的示例或某些內容,即使內容是從源複製的,也會更好。請考慮閱讀[本指南](http://stackoverflow.com/help/how-to-answer),這可能會有所幫助。 – Victor2748 2015-02-18 01:03:14