简体   繁体   中英

open,edit and save xml file with schema using php

Hy... I'm new in XML Schema, XSL,... (I have basic understanding) On web page: http://w3schools.com/xsl/xsl_editxml.asp is shown example for open,edit,save xml file, but with asp. Do anyone know how can i open/edit and save xml file using php for next example:

<?xml version="1.0" encoding="ISO-8859-1"?>
<tools>
 <tool id="1">
  <field id="prodName">
    <value>HAMMER HG2606</value>
  </field>
  <field id="prodNo">
    <value>32456240</value>
  </field>
  <field id="price">
    <value>$30.00</value>
  </field>
 </tool>
<tool id="2">
  <field id="prodName">
    <value>Audi</value>
  </field>
  <field id="prodNo">
    <value>88885</value>
  </field>
  <field id="price">
    <value>$26.00</value>
  </field>
 </tool>
</tools>

and do i need <tool id="2"> or just <tool> is enough. Thanks very much on replay, and i don't need another xsl like shown on w3s, just fine is refresh submitted php file after submit (will do something with ajax after).

I saw replay from Mr. Writman on questions/377632/add-update-and-edit-an-xml-file-with-php but that is for now 2 complex for me...:) is there any simpler answer (solution). Thanks in advance!!!

To validate the XML against a Schema file you can use

Example:

$document = DOMDocument::load('books.xml');

if ($document->schemaValidate('books.xsd')) {
  print 'books.xml does validate against books.xsd';
}

Also see these methods and the examples given on their manual pages:

You will find XML manipulation with DOM covered extensively at SO:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM