I have an XML (first.xml) which looks like ::
<?xml version="1.0" encoding="utf-8"?>
<saw:jobInfo xmlns:saw="com.analytics.web/report/v1.1">
<saw:jobStats>...........</saw:jobStats>
<saw:detailedInfo> .....</saw:detailedInfo>
<saw:fileInfo>..........</saw:fileInfo>
</saw:jobInfo>
The below XML (second.xml) is same as the above but with a different namespace.
<?xml version="1.0" encoding="utf-8"?>
<soap:jobInfo xmlns:soap="urn://bi.webservices/v6">
<soap:jobStats>...........</saw:jobStats>
<soap:detailedInfo> .....</saw:detailedInfo>
<soap:fileInfo>..........</saw:fileInfo>
</soap:jobInfo>
As I have the same element and attribute names in both the xml’s I am using the same xsd file to validate both.
XSD file ::
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="com.analytics.web/report/v1.1"
xmlns="com.analytics.web/report/v1.1"
xmlns:saw="com.analytics.web/report/v1.1"
xmlns:soap="urn://bi.webservices/v6"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
After including xmlns:soap=”urn://bi.webservices/v6″ the schema validation failed for second.xml saying unkown element “soap:jobinfo”. I poked around and found the targetNamespace value should be same as the namespace URI.
Please let me know how to use the same XSD for two different namespaces having different URIs.
Short answer is you can’t. You could, however, if you would be using three XSDs. It would allow you to have all the XSD that matters into one file (Chameleon.XSD), and have two more that simply compose Chameleon.XSD, those two having the namespaces you want.
Chameleon.XSD
JobInfo1.xsd
JobInfo2.xsd
Relationships:
If you want one XSD to validate them all, then you can go and build a fourth one, that imports these two.
OneAll.XSD
Updated relationships: