PHP implements simple addition, deletion, modification, and query (CRUD) operations on xml, xmlcrud

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.