【问题标题】:nested xml document in Simplexml documentSimplexml 文档中的嵌套 xml 文档
【发布时间】:2009-10-25 11:53:28
【问题描述】:

我在使用 simplexml 读取从 web 服务调用返回的 xml 文档时遇到问题。

读取数据没问题,但是一个名为 UserArea 的节点包含一个包含命名空间的嵌套 XML 文档。

从this question 开始,我研究了如何处理子节点。但是,当我调用其中包含此嵌套 XML 的节点时,我会返回 null。

数据如下:

<UserArea>

 <rm:EngineVersion>4.2.0.62</rm:EngineVersion>

 <rm:DocumentFormat>305</rm:DocumentFormat>

 <rm:Industry>AUT</rm:Industry>

 <rm:Department>GEN</rm:Department>

 <rm:HighestDegree year="2004" major="COMPUTER PROGRAMMING">BACHELORS</rm:HighestDegree>

 <rm:ExperienceSummary>

  <rm:Experience>

    <rm:ExperienceKind>Summary</rm:ExperienceKind>

    <rm:Years>11</rm:Years>

    <rm:Detail>A total of 11 years of work experience.</rm:Detail>

  </rm:Experience>

  <rm:Experience>

    <rm:ExperienceKind>HighestIndustry</rm:ExperienceKind>

    <rm:Years>5</rm:Years>

    <rm:Industry>AUT</rm:Industry>

    <rm:Detail>Highest industry-related experience is 5 years in automotive      </rm:Detail>

  </rm:Experience>
 </rm:ExperienceSummary>
</UserArea>

我没有想法,因为代码:

foreach($myObject->UserArea->children as $userAreaXML){

   foreach($userAreaXML->ExperianceSummary as $summary){
      echo $summary->Detail;
   } 
}

只是不起作用。

【问题讨论】:

    标签: php xml simplexml


    【解决方案1】:

    您可能想阅读http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/ .. 解释得再清楚不过了。

    【讨论】:

      【解决方案2】:

      此代码将打印出详细信息

      $experiences = $myObject->ExperienceSummary->Experience;
      
      foreach($experiences as $experience) {
       echo $experience->Detail . "<br>";
      }
      

      【讨论】:

        猜你喜欢
        • 2018-09-19
        • 2018-03-09
        • 2020-11-29
        • 2012-05-11
        • 2021-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-24
        相关资源
        最近更新 更多