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

断了今生、忘了曾经 提交于 2019-12-12 02:44:46

问题


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>

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)

回答1:


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



来源:https://stackoverflow.com/questions/2686086/vb-net-validate-an-xml-against-a-schema-strange-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!