解析名称空间内的提要

时间:2015-02-18 00:21:50

标签: php xml parsing namespaces

我在这里尝试了几种不同的方法,但无济于事。有人可以向我解释如何解析以下类型的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限制)。有人可以解释我将如何通过像这样的提要解析?我已经走得很远了,但似乎仍无法解决这个问题。还请解释为什么你做任何事情才能使这项工作。我必须以这种方式解析几个Feed并且我以前从未处理过这个问题。任何帮助将不胜感激。

谢谢! 克里斯

1 个答案:

答案 0 :(得分: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
}
?>