sgrebnev
Новичок
xml/dom/изменение содержимого узла
вот xml к примеру:
<?xml version="1.0"?>
<constants>
<const id="0">
<name>NUM_ROW_ON_PAGE</name>
<value>5</value>
</const>
<const id="1">
<name>SOME_CONS_ONE</name>
<value>1</value>
</const>
<const id="2">
<name>SOME_CONS_TWO</name>
<value>2</value>
</const>
<const id="3">
<name>SOME_CONS_THREE</name>
<value>3</value>
</const>
</constants>
теперь получить содержимое узла по id с помощью dom объекта я могу так:
function getConstantOnID( $id ) {
global $dom;
$const_array = array();
$consts = $dom->getElementsByTagName("const");
foreach ($consts as $const) {
if ($const -> getAttribute("id") == $id) {
foreach ($const->childNodes as $item) {
if (in_array($item->nodeName, array("name","value") ) ) {
$const_array["id"] = $const -> getAttribute("id");
$const_array[$item->nodeName] = $item->textContent;
}
}
}
}
return $const_array;
}
а терь как изменить содержимое (name/value) узла, найденного по id?
вот xml к примеру:
<?xml version="1.0"?>
<constants>
<const id="0">
<name>NUM_ROW_ON_PAGE</name>
<value>5</value>
</const>
<const id="1">
<name>SOME_CONS_ONE</name>
<value>1</value>
</const>
<const id="2">
<name>SOME_CONS_TWO</name>
<value>2</value>
</const>
<const id="3">
<name>SOME_CONS_THREE</name>
<value>3</value>
</const>
</constants>
теперь получить содержимое узла по id с помощью dom объекта я могу так:
function getConstantOnID( $id ) {
global $dom;
$const_array = array();
$consts = $dom->getElementsByTagName("const");
foreach ($consts as $const) {
if ($const -> getAttribute("id") == $id) {
foreach ($const->childNodes as $item) {
if (in_array($item->nodeName, array("name","value") ) ) {
$const_array["id"] = $const -> getAttribute("id");
$const_array[$item->nodeName] = $item->textContent;
}
}
}
}
return $const_array;
}
а терь как изменить содержимое (name/value) узла, найденного по id?