2012-12-06 2 views
6

두 번째 수준을 가져 오는 최상위 수준 xsd가 주어지면 세 번째 수준을 가져옵니다. 첫 번째 수준에서 세 번째 형식을 사용할 수 있습니까? 아니면 첫 번째가 세 번째를 직접 가져와야합니까? type 만약가져 오기에서 가져온 xsd의 사용 유형

답변

1

당신이 다음에 대해 얘기하는 것입니다 .. 그것은 <xs:Include>하지 <xs:Import> ..

의 그 대답은 다음과 같습니다 파서

아래의 예를 참조 함께 모든 XSD를 연결을 담당 :

,691,363 : 내가 XSD를 설계하는 것입니다 위의 XML의
<?xml version="1.0" encoding="utf-8"?> 
<root> 
    <child>trial</child> 
    <child2>trial2</child2> 
    <trunk> 
    <branch>1</branch> 
    <branch>2</branch> 
    </trunk> 
    <specialchild>test</specialchild> 
</root> 

(210)

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:include schemaLocation="include multiple XSDs2.xsd"/> 
    <xs:element name="root" type ="root"/> 
    <xs:complexType name="root"> 
    <xs:sequence> 
     <xs:element name="child" type="xs:string" /> 
     <xs:element name="child2" type="xs:string" /> 
     <xs:element name="trunk" type="trunk"/> 
     <xs:element name="specialchild" type="specialchild"/> 
    </xs:sequence> 
    </xs:complexType> 
</xs:schema> 
형 트렁크 import multiple XSDs2.xsd 파일에 정의와 연결 (같은 폴더에 존재한다) <xs:include> .. ..를 사용하여 그리고 코드는 다음처럼 보이는

:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:include schemaLocation="include multiple XSDs3.xsd"/> 
    <xs:complexType name="trunk"> 
    <xs:sequence> 
     <xs:element maxOccurs="unbounded" name="branch" type="branch" /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:schema> 

입력 지점이있다 간단한 유형은 include multiple XSDs3.xsd 파일에 정의하고, 코드는 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:simpleType name="branch"> 
    <xs:restriction base="xs:string"/> 
    </xs:simpleType> 
    <xs:simpleType name="specialchild"> 
    <xs:restriction base="xs:string"/> 
    </xs:simpleType> 
</xs:schema> 

* 이제 까다로운 부분은 다음과 같습니다 specialchild이 곳으로 XSD_1에 선언 XSD_3에 정의되어 있으며이 두 XSD는 XSD_2에 의해 연결됩니다. 기본적으로 파서는 모든 XSD를 연결하고 모든 것을 하나로 취급한다는 것을 알 수 있습니다! *

호프가 궁금한 점이 있으시면

3

좋은 질문입니다! 스펙을 읽는 것부터, 나는 정말로 말할 수 없다. 이행 적 수입 문제를 명시 적으로 명시 적으로 다루지는 않습니다. 본서에서

(부품 0), 그들은 단지 수입의 약 수준을 이야기 : 구조 (1 부)에서

, 그것은 또한 만은 해결의 수단 "에 대해 이야기하기 때문에 http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#composition-schemaImport를 가져 직접 정의 http://www.w3.org/TR/xmlschema-0/#import foreign component "(네임 스페이스를 의미한다고 생각합니다)를 사용하면 가져온 스키마를 명시 적으로 처리하는 방법이 필요하다고 가정하는 것이 타당합니다. 즉, 가져 오기의 명시 적 네임 스페이스가 각각 필요합니다. 그 게시물에 대해 가장 관심 무엇

다른 XSD 프로세서 다른 가지고있다 :

구글 검색 다른 사람들이이 문제로 혼동되어 있는지 보여줍니다 행동 - 프로세서의 작성자도 혼란 스러웠다 고 제안했다.

이러한 게시물 (2002 년, 2005 년) 이후로 변경되었을 수도 있지만 현명한 코스는 모든 프로세서에서 작동하므로 직접 가져 오기를 사용하는 것입니다.

내가 말한대로 : 좋은 질문입니다. 여기


은 (이 그것이 다른 ... 다른 XSD 프로세서를 사용하는 사람을 위해 작동을 보장하지 않습니다 물론)는 XSD 프로세서를 확인하는 테스트입니다. 내가 가장 좋아하는 제품 (xmllint)이 이 아니며이 아닌 transitive imports를 발견했습니다.

시험은 세 스키마이다 a.xsd 차례로 수입 을 c.xsd b.xsd 수입;

<!-- a.xsd --> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.c.com" targetNamespace="http://www.a.com"> 
    <xsd:import namespace="http://www.b.com" schemaLocation="b.xsd"/> 
<!-- UNCOMMENT FOR DIRECT IMPORT 
    <xsd:import namespace="http://www.c.com" schemaLocation="c.xsd"/> 
--> 
    <xsd:element name="eg" type="c:TypeC"/> 
</xsd:schema> 

<!-- b.xsd --> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:import namespace="http://www.c.com" schemaLocation="c.xsd"/> 
</xsd:schema> 

<!-- c.xsd --> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.c.com"> 
    <xsd:simpleType name="TypeC"> 
     <xsd:restriction base="xsd:string"/> 
    </xsd:simpleType> 
</xsd:schema> 


<!-- a.xml --> 
<eg xmlns="http://www.a.com">hello world</eg> 

$ xmllint --schema a.xsd a.xml --noout 
a.xsd:6: element element: Schemas parser error : Element 
'{http://www.w3.org/2001/XMLSchema}element', attribute 'type': References from 
this schema to components in the namespace 'http://www.c.com' are not allowed, 
since not indicated by an import statement. 
WXS schema a.xsd failed to compile 

오류 메시지는 다음과 같습니다 : References from this schema to components in the namespace 'http://www.c.com' are not allowed, since not indicated by an import statement., xmllint가의 개발자가 적어도 수입은 이적 아니라는 것을 확신 것을 제안하고 에 정의 된 유형은a.xsd에서 참조 c.xsd.

관련 문제