I have an xml that I wanted to verify against an xsd (with multiple schemas). The xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<Interchange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.abc.com.au/eApplications/Interchange/4.2">
<InterchangeID>19768</InterchangeID>......</Interchange>
This xml didn't pass the validation and was giving me the following error:
The 'http://www.abc.com.au/eApplications/Interchange/4.2:Interchange' element is not declared.
When I introduced namespace with xml like this:
xmlns:ns="http://www.abc.com.au/eApplications/Interchange/4.2"
The error was gone, even I didn't introduce namespace prefix like or with any of the xml tags like:
<ns:Interchange>
<ns:InterchangeID>...
My Findings: The xml passes the validation if I either introduce :ns as a namespace or remove the line completely (after the parent Interchange tag) containing all the namespace references defined and keep it like that:
<Interchange>
<InterchangeId>....
which is obviously not good.
Though I was able to fix this by the method explained above, I want to know the reason behind this as I couldn't find it after going through many links this, A Ten-Minute Guide to XML Namespaces and XML Namespaces Explained
Edit I'm attaching the xsd here:
enter code here
<xs:schema xmlns:eapp="http://www.abc.com.au/eApps/iChange/4.2"
elementFormDefault="qualified"
targetNamespace="http://www.abc.com.au/eApps/iChange/4.2"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="abc_datatypes.xsd"/>
<xs:complexType name="abcType">
<xs:sequence> </xs:sequence>
</xs:complexType>
</xs:schema>
and the xml sample that passes validation is something like:
<soapenv:Envelope xmlns:soapenv="url"
xmlns:orig="url/OServices" xmlns:ns="http://url/eApps/IChange/4.2">
<soapenv:Header/>
<soapenv:Body>
<or:Originate>
<!--Optional:-->
<or:data>
<ns:InID>2229</ns:InID>
<ns:ReceiverID>CFS</ns:ReceiverID>
</or:data>
</or:Originate>
</soapenv:Body>
</soapenv:Envelope>