VB.Net 根据架构验证 xml(奇怪的问题) [英] VB.Net Validate an xml against a schema (strange problem)

查看:43
本文介绍了VB.Net 根据架构验证 xml(奇怪的问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个小型 XML 验证器,它接收一个 XML 文件和一个 XML 架构,并根据该架构验证 XML 文件.除了带有以下内容的 XML 文件外,它运行良好:

I have written a small XML validator, that takes in an XML file and an XML schema and validates the XML files against that schema. It works well, except for an XML file, with this content:

 <?xml version="1.0" encoding="utf-8"?>
<xc:program xmlns:xc="http:\\www.something.com\Schema\XC10" xc:version="4.0.22.0" >
    <xc:namespaceDecls>
        <xc:namespaceDecl xc:namespaceDeclURI="urn:swift:xsd:abc">
            <xc:namespaceDeclPrefix>n</xc:namespaceDeclPrefix>
        </xc:namespaceDecl>
    </xc:namespaceDecls>
</xc:program>

我尝试根据一堆不同的模式验证这个 XML 文件.无论我选择哪种模式,这个 XML 文件都是有效的.我错过了什么?这是相关的一段代码:

I tried to validate this XML file against a bunch of different schemas. No matter which schema I select, this XML file comes out as valid. What is it that I am missing? Here is the relevant piece of code:

//'Create a schema cache and add the given schema to it.
Dim schemaCache As New Schema.XmlSchemaSet

schemaCache.Add(targetNamespace, schemaFilename)

//'Create an XML DOMDocument object.
Dim xmlDom As New XmlDocument

//'Assign the schema cache to the DOM document.
//'schemas collection.
xmlDom.Schemas = schemaCache

//'Load selected file as the DOM document.
xmlDom.Load(xmlFilename)
xmlDom.Validate(AddressOf ValidationCallBack)

推荐答案

您可能有 无法识别根命名空间的问题.在这种情况下,您需要 检查根元素验证状态.

You probably are having that problem with root namespaces being not recognized. In which case you need to check the root element validation status.

这篇关于VB.Net 根据架构验证 xml(奇怪的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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