How to modify xml file using PHP

前端 未结 3 851
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 16:59

I want to modify my xml file in PHP based on the following criteria.

my xml structure look like this:



        
3条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 17:45

    preserveWhiteSpace = FALSE;
                
    $xml->load("markers.xml");
            
    $mar = $xml->getElementsByTagName("marker");
    foreach($mar as $row){
    
    
                $type = $row->getElementsByTagName('type')->item(0);
                $title = $row->getElementsByTagName('title')->item(0);
                $address = $row->getElementsByTagName('address')->item(0);
                $latitude = $row->getElementsByTagName('latitude')->item(0);
                $longitude = $row->getElementsByTagName('longitude')->item(0);
                
                $row->replaceChild($type, $type);
                $row->replaceChild($title, $title);
                $row->replaceChild($address, $address);
                $row->replaceChild($latitude, $latitude);
                $row->replaceChild($longitude, $longitude);
              
                ?>
                
    
    nodeValue = $_POST['type']; $text->nodeValue = $_POST['text']; $address->nodeValue = $_POST['address']; $latitude->nodeValue = $_POST['latitude']; $longitude->nodeValue = $_POST['longitude']; $xml->save("markers.xml"); } } ?>

提交回复
热议问题