Click here to Skip to main content
12,820,077 members (22,030 online)
Rate this:
Please Sign up or sign in to vote.
See more: XML xsd Schema

I am trying to validate an XML file against a schema, which i can achieve without issue normally, however, in this particular schema, there is an imported namespace, that appears to be preventing the validation from happening, as the error being returned is pointing to node of the elements from the imported xsd.

I can manually enter the namespace refrences to the child elements of the XML file and it will validate correctly, however I cannot validate the document, by way of the code.

I have tried a number of things all to no avail:

I have added multiple XSD's to the XMLSchemaSet, which returned a duplicate declaration issue. I assume this is due to the top level schema having an import of the 2nd XMLSchema.

I also tried imports <xmlns="2nd_namespace">, within the declarations, but this seemed to do nothing.

I have also been attempting to apply a namespace to the child elements that I can update manually. When the xDoc is validated against the applied schema it overwrites the previously correct element applied namespaces.

Can I add multiple schemas? am i doing something wrong?
Can i force something in during the validation of a schema.

Any advice would be appreciated here guy's.
Posted 20-Sep-12 23:16pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the following xsl to strip off multiple namespaces:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
  <xsl:output method="xml" indent="no" />
  <xsl:template match="/|comment()|processing-instruction()">
      <xsl:apply-templates />
  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()" />
  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="." />

You can use XslCompiledTransform to transform your xml file, then use it for validation. Also remember to create xsd without multiple namespaces.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Thank you for the response, very interesting will give it a try at a later date. I have managed to resolve this by forcing what was actually 3 differing namespace to the appropriate structures of the XML doc.
The overall root namespace had been overriding all others on the XSD until I removed then re-added at a later point, pre valiation against schema.

Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100