php XMLreader: editing element attributes & values
How I edit the attributes or values of an XML element?
the file:
<element>
<apple type="fruit">red</apple>
</element>
XMLreader:
$xml= new XMLReader();
$xml->open($file);
while($xml->read()){
开发者_开发知识库 if($xml->nodeType == XMLReader::ELEMENT) {
if($xml->getAttribute('type') == "fruit") {
//change attr. and values to:
//apple = cabbage, fruit = vegetable, red = white
}
}
}
Well, in order to edit XML, you must not use a reader class ;-)
Instead, take a look at DOMDocument
or SimpleXML
.
精彩评论