开发者

php XMLreader: editing element attributes & values

开发者 https://www.devze.com 2023-02-28 14:50 出处:网络
How I edit the attributes or values of an XML element? the file: <element> <apple type=\"fruit\">red</apple>

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

精彩评论

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