2010-03-25 2 views
0

노드/하위 노드 구조 내에서 xsd : keyref를 xml 루트 요소의 자식 인 전역 테이블로 참조하려고합니다. 키 XSD : 문서 내의 keyref 필드 여기 xsd : 계층 적 노드 구조의 keyref

I는 또한 XSD를 정의하는 XSD이 예시적인 XML

<?xml version="1.0" encoding="UTF-8"?> 
<Root xmlns="http://www.example.org/keyTest" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.example.org/keyTest keyTest.xsd"> 

<Globals key="key1"/> 
<Globals key="key2"/> 
<Globals key="key3"/> 

<Node> 
<SubNode keyref="key2"/> 
<SubNode keyref="key3"/>  
<SubNode keyref="key1"> 
    <SubNode keyref="key2"> 
     <SubNode keyref="key1"/> 
    </SubNode> 
</SubNode>  
</Node> 
</Root> 

이다. 이 키는 모든 keyref 값이 XML 문서의 시작 부분에서 전역 테이블 내에 있는지 확인해야합니다. 지금까지 나는 selector xpath 표현식의 문제점이 무엇인지 알지 못했습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="http://www.example.org/keyTest" 
     xmlns:tns="http://www.example.org/keyTest" 
     elementFormDefault="qualified"> 

<complexType name="Global"> 
    <attribute name="key" type="string"/> 
</complexType> 

<complexType name="Node" > 
    <sequence maxOccurs="unbounded"> 
     <element name="SubNode" type="tns:Node" minOccurs="0"/> 
    </sequence> 
    <attribute name="keyref" type="string"/> 
</complexType> 

<complexType name="Root"> 
    <sequence> 
     <element name="Globals" type="tns:Global" maxOccurs="unbounded"/> 
     <element name="Node" type="tns:Node" maxOccurs="1"/> 
    </sequence> 
</complexType> 

<element name="Root" type="tns:Root"> 
    <key name="key"> 
     <selector xpath="Global"/> 
     <field xpath="@key"></field> 
    </key> 
    <keyref name="keyref" refer="tns:key"> 
     <selector xpath="//SubNode"/> 
     <field xpath="@keyref"/> 
    </keyref> 
</element> 
문제는 내가 XPath는 검사기로 XPath 식을 때 "// 하위 노드는"이 문서에있는 모든 하위 노드를 선택
keyTest.xsd:30: element selector: Schemas parser error : 
     Element '{http://www.w3.org/2001/XMLSchema}selector', at 
     atribute 'xpath': The XPath expression '//SubNode' could not be compiled. 
     WXS schema keyTest.xsd failed to compile 

를 컴파일 할 수없는 그 xmllint가 문제입니다 W3C 표준에 정의 된대로이 xpath가 selector 표현식 내에서 작동하지 않는 이유는 무엇입니까?

나는 또한 시도했다 .// 서브 노드. 이것은 올바르게 컴파일되지만 잘못된 keyref를 입력하면 유효성을 검증하지 않습니다.

답변

2

내가 찾은 해결책을 공유하고 싶습니다.

올바른 XSD는이 네임 스페이스가없는 것처럼입니다 : 사람에

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="http://www.example.org/keyTest" 
     xmlns:tns="http://www.example.org/keyTest" 
     elementFormDefault="qualified"> 

<complexType name="Global"> 
    <attribute name="key" type="string"/> 
</complexType> 

<complexType name="Node" > 
    <sequence maxOccurs="unbounded"> 
     <element name="SubNode" type="tns:Node" minOccurs="0"/> 
    </sequence> 
    <attribute name="keyref" type="string"/> 
</complexType> 

<complexType name="Root"> 
    <sequence> 
     <element name="Globals" type="tns:Global" maxOccurs="unbounded"/> 
     <element name="Node" type="tns:Node" maxOccurs="1"/> 
    </sequence> 
</complexType> 

<element name="Root" type="tns:Root"> 
    <key name="key"> 
     <selector xpath=".//tns:Globals"/> 
     <field xpath="@key"></field> 
    </key> 
    <keyref name="keyref" refer="tns:key"> 
     <selector xpath=".//tns:SubNode"/> 
     <field xpath="@keyref"/> 
    </keyref> 
    <unique name="uniqKey"> 
     <selector xpath=".//tns:Globals"/> 
     <field xpath="@key"/> 
    </unique> 
</element> 

덕분에이 작업을 시작했다.