후속 요소 정의에서 참조 할 수있는 속성을 정의하려고했습니다.xsd에서 속성을 참조하는 방법
<xs:attribute name="ridref" type="xs:string"/>
나중에 나는이처럼 사용
<xs:element name="coordRegRef">
<xs:complexType>
<!--xs:attribute name="ridref" type="xs:string"/ this works but I want to use ref -->
<xs:attribute ref="ridref" use="required"/>
</xs:complexType>
</xs:element>
XSD는 xmllint가
xmllint --schema pc-ar.xsd pc-ar.xml
으로 잘 컴파일하지만 xmllint가 내가 의미로 해석
pc-ar.xml:41: element coordRegRef: Schemas validity error : Element '{http://pc-ar.xsd}coordRegRef', attribute 'ridref': The attribute 'ridref' is not allowed.
pc-ar.xml:41: element coordRegRef: Schemas validity error : Element '{http://pc-ar.xsd}coordRegRef': The attribute '{http://pc-ar.xsd}ridref' is required but missing.
을 말한다 내 XML 파일은 네임 스페이스를 사용해야합니다. 대신
<coordRegRef ridref="111"/>
왜
의 ridref<coordRegRef fix:ridref="111"/>
(하지 작동하지만 원치 않는)을 검색 하시나요?
내 XSD
<?xml version="1.0"?>
<!-- validate: xmllint - -schema pc-ar.xsd pc-ar.xml -->
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://pc-ar.xsd"
elementFormDefault="qualified"
xmlns="http://pc-ar.xsd"
xmlns:fix="http://pc-ar.xsd">
<!--xs:attribute name="rid" type="xs:integer"/-->
<!--xs:attributeGroup name="ridGroup">
<xs:attribute name="rid" type="xs:integer">
<xs:annotation>
<xs:documentation>entry id</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:attributeGroup-->
<xs:element name="name" type="xs:string"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="idref" type="xs:IDREF"/>
<xs:attribute name="ridref" type="xs:string"/>
<xs:element name="coordRegRef">
<xs:complexType>
<!--xs:attribute name="ridref" type="xs:string"/works-->
<xs:attribute ref="ridref" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="assetRegRef">
<xs:complexType>
<xs:sequence>
<xs:element name="ridref2" type="xs:string"/>
</xs:sequence>
<!--xs:attribute name="ridref" type="xs:string"/works-->
<xs:attribute name="ridref" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="lat">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="-40"/>
<xs:maxInclusive value="-30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="lon" type="xs:decimal"/>
<xs:complexType name="coordRegTableType">
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="lat"/>
<xs:element ref="lon"/>
</xs:sequence>
<xs:attribute name="rid" type="xs:string"/>
<!--xs:attribute ref="fix:id" use="required"/-->
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="assetRegTableType">
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="coordRegRef"/>
<xs:element ref="assetRegRef"/>
</xs:sequence>
<xs:attribute name="rid" type="xs:string"/>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="coordReg" type="fix:coordRegTableType">
<xs:unique name="coordRegNameUniq">
<xs:selector xpath="*"/>
<xs:field xpath="fix:name"/>
</xs:unique>
</xs:element>
<xs:element name="assetReg" type="assetRegTableType">
<xs:unique name="assetRegNameUniq">
<xs:selector xpath="fix:entry"/>
<xs:field xpath="fix:name"/>
</xs:unique>
</xs:element>
<xs:element name="assetExchange">
<xs:complexType>
<xs:sequence>
<xs:element ref="coordReg"/>
<xs:element ref="assetReg"/>
</xs:sequence>
<xs:attribute name="rid" type="xs:integer"/>
<!--xs:attribute ref="id" use="required"/-->
</xs:complexType>
<xs:key name="coordRegKey">
<xs:selector xpath="fix:coordReg/fix:entry"/>
<xs:field xpath="@rid"/>
</xs:key>
<xs:key name="assetRegKey">
<xs:selector xpath="fix:assetReg/fix:entry"/>
<xs:field xpath="@rid"/>
</xs:key>
<xs:keyref name="assetRegKeyRef" refer="assetRegKey">
<xs:selector xpath=".//fix:assetRegRef"/>
<xs:field xpath="@ridref"/>
</xs:keyref>
<xs:keyref name="assetRegKeyRef2" refer="assetRegKey">
<!--xs:selector xpath=".//fix:assetRegRef"/works-->
<!--xs:selector xpath="./*/*/fix:assetRegRef"/works-->
<!--xs:selector xpath="./*/fix:entry/fix:assetRegRef"/works-->
<!--xs:selector xpath="./*/*/fix:assetRegRef"/works-->
<xs:selector xpath=".//fix:assetRegRef"/> <!-- any assetRefRef -->
<xs:field xpath="fix:ridref2"/>
</xs:keyref>
<xs:keyref name="coordRegKeyRef" refer="coordRegKey">
<xs:selector xpath=".//fix:coordRegRef"/>
<xs:field xpath="@ridref"/>
</xs:keyref>
</xs:element>
</xs:schema>
내 XML 테스트 파일이 발견하고는 유효성 검사 오류에서 볼 수 있듯이, 파서가 속성 ridref
을 기대 않지만 그것을해야합니다으로
<?xml version="1.0"?>
<assetExchange
xmlns="http://pc-ar.xsd"
xmlns:fix="http://pc-ar.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pc-ar.xsd pc-ar.xsd"
rid="1">
<coordReg>
<entry id="1" rid="111">
<name>sitea</name>
<lat>-31.23</lat>
<lon>151</lon>
</entry>
<entry id="2" rid="222">
<name>siteb</name>
<lat>-31.23</lat>
<lon>151</lon>
</entry>
<entry id="3" rid="333">
<name>sitec</name>
<lat>-31.23</lat>
<lon>151</lon>
</entry>
</coordReg>
<assetReg>
<entry id="11" rid="11">
<name>deva</name>
<coordRegRef fix:ridref="111"/>
<assetRegRef ridref="aa"><ridref2>aa</ridref2></assetRegRef>
</entry>
<entry id="22" rid="22">
<name>devb</name>
<coordRegRef ridref="2212"/>
<assetRegRef ridref="11"><ridref2>11</ridref2></assetRegRef>
</entry>
<entry id="33" rid="33">
<name>devc</name>
<coordRegRef ridref="333"/>
<assetRegRef ridref="44"><ridref2>44</ridref2></assetRegRef>
</entry>
</assetReg>
</assetExchange>
도 http://stackoverflow.com/questions/8903768/unqualified-xsd-global-attribute-references?rq=1 볼 – philcolbourn