简体   繁体   English

使用php使用架构打开,编辑和保存xml文件

[英]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. 嗨...我是XML Schema,XSL的新手,...(我有基本的了解)在网页上: http : //w3schools.com/xsl/xsl_editxml.asp显示为打开,编辑,保存xml的示例文件,但使用asp。 Do anyone know how can i open/edit and save xml file using php for next example: 有谁知道我如何使用php打开/编辑和保存xml文件作为下一个示例:

<?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. 我需要<tool id="2">还是仅仅<tool>就足够了。 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). 非常感谢重播,并且我不需要像w3s所示的另一个xsl,只需在提交后刷新提交的php文件即可(之后将用ajax做一些事情)。

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). 我看到了Writman先生在问题/ 377632 / add-update-and-edit-an-xml-file-with-php上的重放,但这对我来说现在很复杂2 ... :)有没有更简单的答案(解决方案)。 Thanks in advance!!! 提前致谢!!!

To validate the XML against a Schema file you can use 要针对Schema文件验证XML,可以使用

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: 您将在SO上找到有关DOM的XML操作的广泛介绍:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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