Question

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)
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top