简体   繁体   English

VB.Net针对模式验证xml(奇怪的问题)

[英]VB.Net Validate an xml against a schema (strange problem)

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. 我写了一个小的XML验证器,它接收XML文件和XML模式,并根据该模式验证XML文件。 It works well, except for an XML file, with this content: 除了具有以下内容的XML文件外,它运作良好:

 <?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>

I tried to validate this XML file against a bunch of different schemas. 我试图针对一堆不同的模式来验证该XML文件。 No matter which schema I select, this XML file comes out as valid. 无论我选择哪种模式,该XML文件都是有效的。 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 . 在这种情况下,您需要检查根元素验证状态

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

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