Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML xsd Schema
Hi,
 
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 22:16pm
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="no" />
  <xsl:template match="/|comment()|processing-instruction()">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()" />
    </xsl:element>
  </xsl:template>
  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>
 
You can use XslCompiledTransform to transform your xml file, then use it for validation. Also remember to create xsd without multiple namespaces.
  Permalink  

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

  Print Answers RSS
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2014
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