<?php
$xmlpatch = 'index.xml';
$doc = new DOMDocument();
$doc -> formatOutput = true;
if($doc -> load($xmlpatch)) {
$document = $doc -> documentElement;
$elm = $document -> getElementsByTagName('item');
$_id = '2';
$_title = 'url has been changed';
$_content = '内容has been changed';
$checkexist = 0;
foreach ($elm as $new) {
if($new -> getAttribute('id') == $_id) {
$op = $new -> getElementsByTagName('op');
//$op -> setAttribute('url', $_title);
//$op -> nodeValue = $_content;
foreach ($op as $opnew) {
$opnew -> setAttribute('url', $_title);
$opnew -> nodeValue = $_content;
}
$checkexist = 1;
}
}
if($checkexist == 0) {
echo $_id . ' is not found in ' . $xmlpatch;
} else {
$doc -> save($xmlpatch);
echo $_id . ' has been changed';
}
} else {
echo 'xml file loaded error!';
}
$xmlpatch = 'index.xml';
$doc = new DOMDocument();
$doc -> formatOutput = true;
if($doc -> load($xmlpatch)) {
$document = $doc -> documentElement;
$elm = $document -> getElementsByTagName('item');
$_id = '2';
$_title = 'url has been changed';
$_content = '内容has been changed';
$checkexist = 0;
foreach ($elm as $new) {
if($new -> getAttribute('id') == $_id) {
$op = $new -> getElementsByTagName('op');
//$op -> setAttribute('url', $_title);
//$op -> nodeValue = $_content;
foreach ($op as $opnew) {
$opnew -> setAttribute('url', $_title);
$opnew -> nodeValue = $_content;
}
$checkexist = 1;
}
}
if($checkexist == 0) {
echo $_id . ' is not found in ' . $xmlpatch;
} else {
$doc -> save($xmlpatch);
echo $_id . ' has been changed';
}
} else {
echo 'xml file loaded error!';
}
exit;
?>