Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Use the following xsl to strip off multiple namespaces:
XML
<?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.
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900