VB.Net根据模式验证xml(奇怪的问题)

问题描述:

我已经编写了一个小型XML验证程序,它接收XML文件和XML模式并根据该模式验证XML文件。它运行良好,除了一个XML文件,这个内容:VB.Net根据模式验证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> 

我试图验证这个XML文件对一堆不同的模式。 无论选择哪个模式,这个XML文件都是有效的。我错过了什么? 下面是相关的代码:

//'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) 

你可能正在为that problem与根命名空间而无法识别。在这种情况下,您需要check the root element validation status