开发者

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>HA开发者_JAVA技巧MMER 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

  • DOMDocument::schemaValidate — Validates a document based on a schema
  • DOMDocument::schemaValidateSource — Validates a document based on a schema

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:

  • DOMDocument::load — Load XML from a file
  • DOMDocument::getElementById — Searches for an element with a certain id
  • DOMDocument::save — Dumps the internal XML tree back into a file

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

  • https://stackoverflow.com/search?q=DOM+php
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜