[英]open,edit and save xml file with schema using php
嗨...我是XML Schema,XSL的新手,...(我有基本的了解)在網頁上: http : //w3schools.com/xsl/xsl_editxml.asp顯示為打開,編輯,保存xml的示例文件,但使用asp。 有誰知道我如何使用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>
我需要<tool id="2">
還是僅僅<tool>
就足夠了。 非常感謝重播,並且我不需要像w3s所示的另一個xsl,只需在提交后刷新提交的php文件即可(之后將用ajax做一些事情)。
我看到了Writman先生在問題/ 377632 / add-update-and-edit-an-xml-file-with-php上的重放,但這對我來說現在很復雜2 ... :)有沒有更簡單的答案(解決方案)。 提前致謝!!!
要針對Schema文件驗證XML,可以使用
DOMDocument::schemaValidate
—根據架構驗證文檔 DOMDocument::schemaValidateSource
—根據架構驗證文檔 例:
$document = DOMDocument::load('books.xml');
if ($document->schemaValidate('books.xsd')) {
print 'books.xml does validate against books.xsd';
}
另請參見這些方法以及其手冊頁上給出的示例:
DOMDocument::load
—從文件加載XML DOMDocument::getElementById
—搜索具有特定ID的元素 DOMDocument::save
—將內部XML樹轉儲回文件 您將在SO上找到有關DOM的XML操作的廣泛介紹:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.