使用 php 针对 xsd 验证 xml 文件 [英] validate a xml file against a xsd using php

查看:49
本文介绍了使用 php 针对 xsd 验证 xml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据 xsd 验证 xml 文件?有 domdocument::schemaValidate() 但它没有说明错误在哪里.有什么课吗?从头开始制作解析器有什么价值吗?或者只是重新发明轮子,

how to validate a xml file against a xsd? there is domdocument::schemaValidate() but It does not tell where are the errors. is there any class for that? does it have any worth making that parser from scratch? or is it just reinventing he wheel,

推荐答案

这段代码的作用是:

$xml= new DOMDocument();
$xml->loadXML(<A string goes here containing the XML data>, LIBXML_NOBLANKS); // Or load if filename required
if (!$xml->schemaValidate(<file name for the XSD file>)) // Or schemaValidateSource if string used.
{
   // You have an error in the XML file
}

请参阅http://php.net/manual/en/domdocument 中的代码.schemavalidate.php 检索错误.

贾斯汀在 redwiredesign dot com 2006 年 11 月 8 日 03:32 发表.

justin at redwiredesign dot com 08-Nov-2006 03:32 post.

这篇关于使用 php 针对 xsd 验证 xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆