PHP - XML - Modifying Node and Attribute Values
来源:互联网 发布:break java 编辑:程序博客网 时间:2024/06/05 15:36
Use SimpleXML to read the XML file, assign new values to elements or attributes, and save the changes back to the file:
- <?php
- // read XML tree
- $xml = simplexml_load_file("data.xml")↩
- or die("ERROR: Cannot create SimpleXML object");
- // alter value of node <weight>
- $xml->weight = 3000;
- // alter value of attribute <weight units=>
- $xml->weight['units'] = "gm";
- // write modified tree back to file as XML string
- file_put_contents("data.xml", $xml->asXML()) ↩
- or die("ERROR: Could not write to file");
- echo "XML file successfully updated";
- ?>
Comments
In this listing, the original XML file is first read in, and elements and attributes are altered by assigning new values to the corresponding object properties and arrays. The asXML() method, typically used to output the XML tree as a string, is combined with the file_put_contents() function to overwrite the original XML document with the new data.
- PHP - XML - Modifying Node and Attribute Values
- PHP - Retrieving Node and Attribute Values From XML
- XML DOM Get Node Values
- Get and Set Attribute Values with Properties
- Groovy Samples (attribute validators,transient attribute value calculations,bind variable and attribute default values )
- Class Attribute and XML doc
- How to: Qualify XML Element and XML Attribute Names
- Modifying
- python xml parse and modify node
- Hacking Enums and Modifying "final static" Fields
- AXML中的node attribute
- AttributeError: Values instance has no attribute 'settings'
- 'numpy.ndarray' object has no attribute 'values'
- MISSION AND VALUES
- FORALL(INDICES AND VALUES)
- Primitive values and Objects
- Integral Types and Values
- Identifying multiple/single values of metadata and recording into XML via .NET Client Object Model
- Microsoft JET Database Engine (0x80004005) 未指定的错误
- Javascript 常用代码
- C# 获得当前的路径
- Javascript+CSS实现Flash动态新闻效果(pp原创)
- (转)eclipse常用快捷方式
- PHP - XML - Modifying Node and Attribute Values
- jabsorb笔记
- 怎样写一个拼写检查器
- Blizzcon今晚开幕 开放《Diablo 3》试玩
- Beginning CSS: Cascading Style Sheets for Web Design
- 三十岁前你大可不要去在乎的18件事
- Using XML with Legacy Business Applications
- Formal Software Development
- java面试提