开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜