【问题标题】:FOR loop:how to get values from a xml page using for loop?FOR 循环:如何使用 for 循环从 xml 页面获取值?
【发布时间】:2013-01-31 06:30:44
【问题描述】:

我的xml页面:

<item>
<title geoid="1198">District of Columbia</title>
<description cong_dist="Delegate District (at Large) 98">DC - Delegate District (at Large) 98 <br/> No of Incidents: 1436</description>
<latitude>38.8933115</latitude>
<longitude>-77.0146475</longitude>
<georss:polygon>38.934311 -77.1199 38.939834989364 -77.112868886998 38.94641 -77.1045 38.94891 -77.1007 38.95651 -77.0915 38.960871062931 -77.085827416011 38.967245703105 -77.077535703105 38.971616050926 -77.07185104194 38.98511 -77.054299 38.986557824794 -77.0523733.885112 -76.919295 38.884412 -76.920195 38.881242218815 -76.92424312618 886998 38.934311 -77.1199</georss:polygon>
</item>

我必须在for循环中通过标签名称一一取值。

for(?){
     geom = items[i].childNodes[j].childNodes[0].nodeValue;
}

这个值在for循环中迭代,我必须将这些值存储在geom中。

如何从"sample.xml" xml 页面获取值。

我必须通过tag name 取值。

如何做到这一点??

【问题讨论】:

    标签: php xml xml-parsing xml-serialization simplexml


    【解决方案1】:

    您可以使用它的 SimpleXMLElement 类循环遍历要迭代的 Item 的长度

    example and documentation

    我更喜欢并建议使用 foreach

    【讨论】:

      猜你喜欢
      • 2013-04-24
      • 2013-09-22
      • 2018-05-21
      • 2017-09-17
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多