我有一个
XML(first.xml),看起来像::
- <?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>
下面的XML(second.xml)与上面的相同,但具有不同的命名空间.
- <?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>
因为我在xml中都有相同的元素和属性名称,所以我使用相同的xsd文件来验证两者.
XSD文件::
- <?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">
在包含xmlns:soap =“urn://bi.webservices/v6”之后,对于second.xml说未知元素“soap:jobinfo”的模式验证失败.我四处寻找并发现targetNamespace值应该与命名空间URI相同.
请让我知道如何为具有不同URI的两个不同命名空间使用相同的XSD.
简短的回答是你不能.但是,您可以使用三个XSD.它允许你将所有重要的XSD集成到一个文件(Chameleon.XSD)中,并且还有两个简单地组成Chameleon.XSD,这两个具有你想要的命名空间.
Chameleon.XSD
- <?xml version="1.0" encoding="utf-8"?>
- <!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
- <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:element name="jobInfo">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="jobStats" type="xsd:string" />
- <xsd:element name="detailedInfo" type="xsd:string" />
- <xsd:element name="fileInfo" type="xsd:string" />
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
JobInfo1.xsd
- <?xml version="1.0" encoding="utf-8"?>
- <!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
- <xsd:schema xmlns="com.analytics.web/report/v1.1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="com.analytics.web/report/v1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:include schemaLocation="Chameleon.xsd"/>
- </xsd:schema>
JobInfo2.xsd
- <?xml version="1.0" encoding="utf-8"?>
- <!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
- <xsd:schema xmlns="urn://bi.webservices/v6" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn://bi.webservices/v6" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:include schemaLocation="Chameleon.xsd"/>
- </xsd:schema>
关系:
如果你想要一个XSD验证它们,那么你可以去构建第四个,导入这两个.
OneAll.XSD
- <?xml version="1.0" encoding="utf-8"?>
- <!--XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com)-->
- <xsd:schema xmlns="urn:tempuri-org:XSD:1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:tempuri-org:XSD:1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:import namespace="com.analytics.web/report/v1.1" schemaLocation="JobInfo1.xsd"/>
- <xsd:import namespace="urn://bi.webservices/v6" schemaLocation="JobInfo2.xsd"/>
- </xsd:schema>
更新关系: