On twitter

RT @christiney35: 最近很多人介紹新朋友合作,真好。我也需要人家介紹 Python 工程師耶~快來吧,Python 工程師!! #fb

follow me on twitter

[PHP] XML Schema 驗證 0

記得之前再翻 PHP Manual 時, 看到 DOM 裡有 schemaValidate 這個東西, 也因為工作需要, 所以來試一下, 還真方便好用。

$xml = file_get_contents('http://tzangms.com/foo.xml');
$dom = new DOMDocument;
$dom->loadXML($xml);

$is_validate = $dom->schemaValidate('bar.xsd');

或是用 load 讀 xml 檔名

$dom = new DOMDocument;
$dom->load('foo.xml');

$is_validate = $dom->schemaValidate('bar.xsd');

另外 xsd 的部分, 也有 schemaValidateSource 可用
$dom->schemaValidateSource($xsd);

April 1st, 2008 Programming Tags: , , ,

Leave a Reply

Partners of Oceanic / 人生海海

jiwosca