PHP implements simple addition, deletion, modification, and query (CRUD) operations on xml, xmlcrud
This example describes how PHP implements simple addition, deletion, modification, and query (CRUD) operations on xml. We will share this with you for your reference. The details are as follows:
Assume the following xml file is available:
<?xml version="1.0" encoding="UTF-8"?><setting> <preferTime>55.8</preferTime> <playerValue>56</playerValue> <reduceValue>40</reduceValue> <reduceTime>339</reduceTime></setting>
How to Use php to perform CRUD on it? In fact, this simple xml file is usedSimpleXMlEven better. You can operate on it like this:
<? Php // get data GET the config dataif (isset ($ _ GET ["type"]) {if ($ _ get ["type"] = "get ") {$ xml = simplexml_load_file (".. /config. xml "); $ config = array (" preferTime "=> $ xml-> preferTime. "", "playerValue" => $ xml-> playerValue. "", "performancevalue" => $ xml-> performancevalue. "", "performancetime" => $ xml-> performancetime. ""); echo json_encode ($ config);} // update the config data if ($ _ GET ["type"] = "update ") {$ xml = simplexml_load_file (".. /c Onfig. xml "); $ xml-> preferTime = $ _ GET [" data "] [" preferTime "]; $ xml-> playerValue = $ _ GET ["data"] ["playerValue"]; $ xml-> performancevalue = $ _ GET ["data"] ["performancevalue"]; $ xml-> performancetime = $ _ GET ["data"] ["performancetime"]; $ xml-> asXML (".. /config. xml "); echo json_encode (" save success! ");}}
For more details, refer to PHP official usage examples and API description.
PS: Here are some online tools for xml operations for your reference:
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Online formatting XML/online compression XML:
Http://tools.jb51.net/code/xmlformat
XMLOnline compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress
XMLCode Online formatting and beautification tools:
Http://tools.jb51.net/code/xmlcodeformat