2011-11-08 14 views
5

मैं नीचे की तरह एक XSD फ़ाइल के बीच संबंधों को परिभाषित करने के लिए: तो यहाँ मैं परिभाषित किया हैXSD - कैसे दो तत्वों

<finder-def name="circleFinder" description="Finds circle based on msisdn" class="com.onmobile.reporting.etl.processor.common.propertyplugins.CircleIdPropertyPlugin" /> 

<dimension name="circleId"> 
    <finder name="circleFinder" /> 
</dimension> 

,:

<element name="finder-def" minOccurs="0" maxOccurs="unbounded"> 
    <complexType> 
     <attribute name="name" type="string" use="required"></attribute> 
     <attribute name="description" type="string"></attribute> 
     <attribute name="class" type="string" use="required"></attribute> 
    </complexType> 
</element> 

<complexType name="Dimension"> 
    <sequence> 
     <element name="finder" type="Finder" minOccurs="0" maxOccurs="1"/> 
    </sequence> 
</complexType> 

<complexType name="Finder"> 
    <attribute name="name" type="String" use="required"/> 
</complexType> 

एक्सएमएल फ़ाइल ऊपर XSD फ़ाइल से मेल खाती है नीचे है एक finder-def यानी circleFinder और फिर finder-deffinder तत्व के माध्यम से संदर्भित करना चाहते हैं।

तो सवाल मैं मान्य कर सकते हैं कैसे है कि findercircleFinder अपने defination finder-def

+0

एक वैध और compltete .xml और एक वैध और पूर्ण .xsd नमूना प्रदान करें (मैं इसे प्रमाणित करने के लिए एक सा स्वरूपित है)। – FailedDev

उत्तर

2

में बस एक और तरीका स्कीमा के अंदर आईडी और IDREF प्रकार का उपयोग करने कि ऊपर बताया गया है। उदाहरण: नमूना XML:

<?xml version="1.0" encoding="UTF-8"?> 
<f:root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:f="http://test.com/finder" xsi:schemaLocation="http://test.com/finder finder.xsd"> 

<f:finder-def name="circleFinder" description="Finds circle based on msisdn" 
       class="com.onmobile.reporting.etl.processor.common.propertyplugins.CircleIdPropertyPlugin"/> 

<f:dimension name="circleId"> 
    <f:finder name="circleFinder"/> 
</f:dimension> 
</f:root> 

XSD स्कीमा

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="http://test.com/finder" 
     xmlns:tns="http://test.com/finder" 
     elementFormDefault="qualified" attributeFormDefault="unqualified"> 
<xsd:element name="root"> 
    <xsd:complexType> 
     <xsd:sequence> 
      <xsd:element name="finder-def" type="tns:finder-def" minOccurs="0" maxOccurs="unbounded"/> 
      <xsd:element name="dimension" type="tns:Dimension" minOccurs="0" maxOccurs="unbounded"/> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 
<xsd:complexType name="finder-def"> 
    <xsd:attribute name="name" type="xsd:ID" use="required"/> 
    <xsd:attribute name="description" type="xsd:string"/> 
    <xsd:attribute name="class" type="xsd:string" use="required"/> 
</xsd:complexType> 
<xsd:complexType name="Dimension"> 
    <xsd:sequence> 
     <xsd:element name="finder" type="tns:Finder" minOccurs="0" maxOccurs="1"/> 
    </xsd:sequence> 
    <xsd:attribute name="name" type="xsd:string"/> 
</xsd:complexType> 
<xsd:complexType name="Finder"> 
    <xsd:attribute name="name" type="xsd:IDREF" use="required"/> 
</xsd:complexType> 
</xsd:schema> 
+0

@ विक्टर +1 - उपरोक्त दृष्टिकोण में एक समस्या यह है कि अब जेएक्सबी का उपयोग कर उपरोक्त एक्सएसडी से उत्पन्न जावा वर्गों में 'स्ट्रिंग' के बजाय 'ऑब्जेक्ट' प्रकार की 'नाम' संपत्ति है। और मैं विभिन्न स्थानों पर उन जेनरेट कक्षाओं का उपयोग कर रहा था। तो इसके लिए कोई और तरीका है? –

+0

+1 - JAXB और '@ XmlID' /' @ XmlIDREF' की अधिक जानकारी के लिए देखें: http://blog.bdoughan.com/2010/10/jaxb-and-shared-references-xmlid-and.html –

+0

मेक प्रकार स्ट्रिंग के रूप में "नाम" और आईडीआरईएफ प्रकार का एक और elment "ref" जोड़ें। इसके अलावा आप "खोजक" तत्व के लिए आईडीआरईएफ के आंतरिक तत्व को जोड़ सकते हैं और इसमें एक जैक्सबी एनोटेशन जोड़ सकते हैं xsd: एनोटेशन-> xsd: appinfo-> jaxb: property-> jaxb: baseType value com.test.finder.finder-def ताकि xsd-java वर्ग पीढ़ी के बाद तत्व सही प्रकार का हो। –

संबंधित मुद्दे