I'm trying to a update an existing schema to use its own namespace, so I can import it into another schema later and make it clear the types being used are from the imported schema.
I tried changing the default and targeted namespaces but it's caused the schema validation to break and hide the root node. From what I can see i've hidden my root element in another namespace but I am unsure how to configure this to get my desired result.
Here is a basic example of what I've tried
XML
<Parent Id="P">
<Child Id="C"/>
</Parent>
XSD
<xsd:schema targetNamespace="http://myNameSpace.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://myNameSpace.com"
elementFormDefault="qualified" >
<xsd:element name="Child">
<xsd:complexType>
<xsd:attribute name="Id" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Parent">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Child" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="Id" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
Validation
Not valid.
Error - Line 1, 19: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 19; cvc-elt.1: Cannot find the declaration of element 'Parent'.
You need to make a few changes to your XML:
xmlns="http://myNameSpace.com"
toP
.xsi:schemaLocation
to provide a hint to the XSD to use.And to your XSD:
Child
declaration from theParent
declaration.Altogether then, this XML,
will then be valid against this XSD,
as requested.