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

VB.Net根据模式验证xml(奇怪的问题),xml,vb.net,schema,xml-validation,Xml,Vb.net,Schema,Xml Validation,我编写了一个小型XML验证器,它接收XML文件和XML模式,并根据该模式验证XML文件。除了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:n

我编写了一个小型XML验证器,它接收XML文件和XML模式,并根据该模式验证XML文件。除了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>
您可能正在使用无法识别的根命名空间。在这种情况下,你需要这样做

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