0

我的 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>
</item>

而且我必须在其中添加一个变量。

该变量包含另一个 xml 响应:

 var polygon=xmlDoc.getElementsByTagName("georss:polygon");

<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.07753570311 -77.015598 38.97441 -77.013798 38.97011 -77.00829238.967245703105 -77.077535703105 38.960871062931 -77.085827416011 38.95651 -77.0915 38.94891 -77.1007 38.94641 -77.1045 38.939834989364 -77.112868886998 38.934311 -77.1199</georss:polygon>

我将这些值存储为变量polygon

polygon 所以我必须在项目标签中加入这些值。

我该怎么办?

4

1 回答 1

0

简单的:

$sxe = new SimpleXMLElement($response_xml);
$sxe->addChild("polygon", $polygon);
$sxe->saveXML("new_updated.xml");
//echo $sxe->asXML();

如果响应 XML 文件在磁​​盘上:

$sxe = simplexml_load_file("response.xml");
于 2013-02-04T09:43:45.140 回答