VB.Net Validate an xml against a schema (strange problem)
Posted
by Apeksha
on Stack Overflow
See other posts from Stack Overflow
or by Apeksha
Published on 2010-04-21T19:48:06Z
Indexed on
2010/04/21
19:53 UTC
Read the original article
Hit count: 437
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)
© Stack Overflow or respective owner