在PHP中迭代XML

时间:2014-02-10 15:18:27

标签: php xml simplexml

我的XML文件如下所示

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
  <soapenv:Body>
    <ns:queryBroadcastDetailResponse xmlns:ns="http://com/everbridge/ws3">
      <ns:return type="com.nnn.api.messaging.BroadcastDetailResponse">
        <ns:detailBeans type="com.nnn.api.messaging.BroadcastDetailBean">
          <ns:memberBeans type="com.nnn.api.messaging.MessagingMemberInfoBean">
            <ns:contactInfoBeans type="com.nnn.api.messaging.ContactInfoBean">
              <ns:callResult>E-Mail Not Confirmed</ns:callResult>
              <ns:contactPath>john.doe@website.com</ns:contactPath>
            </ns:contactInfoBeans>
            <ns:firstName>John</ns:firstName>
            <ns:lastName>Doe</ns:lastName>
          </ns:memberBeans>
          <ns:memberBeans type="com.nnn.api.messaging.MessagingMemberInfoBean">
            <ns:contactInfoBeans type="com.nnn.api.messaging.ContactInfoBean">
              <ns:callResult>E-Mail Not Confirmed</ns:callResult>
              <ns:contactPath>jane.doe@website.com</ns:contactPath>
            </ns:contactInfoBeans>
            <ns:firstName>Jane</ns:firstName>
            <ns:lastName>Doe</ns:lastName>
          </ns:memberBeans>
          <ns:messageBean type="com.nnn.api.messaging.MessageBean">
            <ns:broadcastId>123456</ns:broadcastId>
            <ns:duration>20</ns:duration>
            <ns:language>English (US)</ns:language>
          </ns:messageBean>
          <ns:totalConfirmed>0</ns:totalConfirmed>
          <ns:totalUnconfirmed>16</ns:totalUnconfirmed>
        </ns:detailBeans>
        <ns:errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
        <ns:status>SUCCESS</ns:status>
        <ns:statusMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
      </ns:return>
    </ns:queryBroadcastDetailResponse>
  </soapenv:Body>
</soapenv:Envelope>

我正在努力获取保存在<ns:memberBeans>内的数据,就像我需要callResultcontactPathfirstNamelastName一样每个memberBeans(有很多)。

我相信我会为此使用内置的SimpleXML类,但我无法从中实际提取内容。我已经阅读了大量的教程,并在Stackoverflow上阅读了类似的答案,但直到现在它们都没有用。

0 个答案:

没有答案