[由于问题不明确而更新] 谢谢你指出这个@hakre
我遇到的问题是,我有这些脚本:
我有这个xml文档:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Placemark>
<name>Chelsea</name>
<Snippet>London</Snippet>
<Point>
<coordinates>-0.2, 51.2,0.000000</coordinates>
</Point>
<id>1</id>
</Placemark>
<Placemark>
<name>World</name>
<Snippet>Willingdon </Snippet>
<Point>
<coordinates>-0.2,50.2,0.000000</coordinates>
</Point>
<id>2</id>
</Placemark>
</Document>
</kml>
并使用此javascript我调用delete.php:
function send2del(d){
$.ajax({
url : 'delete.php',
type : 'POST',
data : { what : $(d).data('id') },
success : function(){
$(d).closest('tr').fadeOut('slow');
}
});
return false;
};
我试图删除地标,使用ID,这是我的delete.php:
<?php
if (isset($_POST['what'])) {
$id = $_POST['what'];
$doc = new DOMDocument;
$doc->load('placemarks.xml');
$shops = $doc->getElementsByTagName('Placemark');
foreach ($shops as $shop) {
$ids = $shop->getElementsByTagName('id');
if ($ids->item(0)->nodeValue == $id) {
$shop->parentNode->removeChild($shop);
}
}
echo $doc->saveXML();
}
?>
但它不起作用。 我尝试使用simpleXML,但没有成功。你能给我一些关于这个问题的指导吗?或者,如果您能帮助我使用simpleXML解决方案,我将非常感激。
答案 0 :(得分:0)
我测试了你的代码。它会根据它删除元素。也许问题在于使用的ID?
之前和之后:
在:
<kml xmlns="http://earth.google.com/kml/2.2">
<document>
<placemark>
<name>Chelsea</name>
<snippet>London</snippet>
<point>
<coordinates>-0.2, 51.2,0.000000</coordinates>
</point>
<id>1</id>
</placemark>
<placemark>
<name>World</name>
<snippet>Willingdon </snippet>
<point>
<id>2</id>
</placemark>
</document>
</kml>
在:
<kml xmlns="http://earth.google.com/kml/2.2">
<document>
<placemark>
<name>World</name>
<snippet>Willingdon </snippet>
<point>
<coordinates>-0.2,50.2,0.000000</coordinates>
</point>
<id>2</id>
</placemark>
</document>
</kml>