2012-03-30 14 views
34

मैं गुणों और बाल तत्वों (यदि संभव हो) दोनों तत्व को परिभाषित करने के लिए सही वाक्यविन्यास जानना चाहता हूं। उदाहरण के लिए:एक्सएसडी तत्व दोनों गुणों और बाल तत्वों के साथ

<component type="A" binding="B"> 
    <operation name="X"> 
    <input type="C" /> 
    </operation> 

    <event name="Y"> 
    <output type="D" /> 
    </event> 
</component> 

जैसा कि आप देख सकते हैं, दोनों घटक घटक, संचालन और घटना दोनों गुण और बाल तत्व हैं। क्या एक्सएसडी में इसे परिभाषित करना संभव है? कैसे?

बहुत बहुत धन्यवाद!

उत्तर

35

यह एक XSD अपने XML मिलान परिभाषित करने के लिए एक संभव तरीका है; एक्सएसडी सीखते समय, आप एक या अधिक एक्सएमएल नमूना फाइलों से शुरू होने वाले आपके लिए एक्सएसडी का अनुमान लगाने वाले टूल की सहायता नामांकित कर सकते हैं।

<?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="component"> 
    <xsd:complexType> 
     <xsd:sequence> 
     <xsd:element name="operation"> 
      <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element name="input"> 
       <xsd:complexType> 
        <xsd:attribute name="type" type="xsd:string" use="required" /> 
       </xsd:complexType> 
       </xsd:element> 
      </xsd:sequence> 
      <xsd:attribute name="name" type="xsd:string" use="required" /> 
      </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="event"> 
      <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element name="output"> 
       <xsd:complexType> 
        <xsd:attribute name="type" type="xsd:string" use="required" /> 
       </xsd:complexType> 
       </xsd:element> 
      </xsd:sequence> 
      <xsd:attribute name="name" type="xsd:string" use="required" /> 
      </xsd:complexType> 
     </xsd:element> 
     </xsd:sequence> 
     <xsd:attribute name="type" type="xsd:string" use="required" /> 
     <xsd:attribute name="binding" type="xsd:string" use="required" /> 
    </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 

आप यह वाकथ्रू रूप में, आप मिनट/maxOccurs, उपयोग (आवश्यक/वैकल्पिक), पुन: उपयोग परिभाषाओं, आदि में सुधार करने शुरू कर सकते हैं एक उत्पन्न XSD एक अच्छा प्रारंभिक बिंदु है, लेकिन आम तौर पर एक ही रास्ता या संपादित किया जा रहा समाप्त होता है एक और ...

+24

मुझे लगता है कि इसके लिए आवश्यक है कि 'XSD: attribute's: sequence' से पहले' XSD आता है। –

+5

हां, ठीक वही विपरीत जो आप उम्मीद करेंगे, वास्तविक xml में गुण तत्वों के सामने आते हैं। –

+4

एक्सएमएल स्कीमा डिजाइनरों से खराब डिजाइन निर्णय, एक्सएसडी को पढ़ने के लिए कड़ी मेहनत कर रहा है, काउंटर अंतर्ज्ञानी होने के अलावा। जटिल टाइप के अंदर किसी भी क्रम में विशेषता और अनुक्रम इत्यादि रखने की अनुमति होनी चाहिए थी –

3

मैं नीचे एक समाधान है कि काम करता है दे रहा हूं,:

<xs:simpleType name="inputTypeType"> 
     <xs:restriction base="xs:string" /> 
</xs:simpleType> 

<xs:complexType name="inputType"> 
    <xs:attribute name="type" type="inputTypeType"/>    
</xs:complexType> 

<xs:simpleType name="operationNameType"> 
     <xs:restriction base="xs:string" /> 
</xs:simpleType> 

<xs:complexType name="operationType"> 
    <xs:sequence> 
    <xs:element name="input" type="inputType" /> 
    </xs:sequence> 
    <xs:attribute name="name" type="operationNameType"/> 
</xs:complexType> 



<xs:simpleType name="outputTypeType"> 
     <xs:restriction base="xs:string" /> 
</xs:simpleType> 

<xs:complexType name="outputType"> 
    <xs:attribute name="type" type="outputTypeType"/>   
</xs:complexType> 

<xs:simpleType name="eventNameType"> 
     <xs:restriction base="xs:string" /> 
</xs:simpleType> 

<xs:complexType name="eventType"> 
    <xs:sequence> 
    <xs:element name="output" type="outputType" /> 
    </xs:sequence> 
    <xs:attribute name="name" type="eventNameType"/> 
</xs:complexType> 


<xs:simpleType name="typeType"> 
     <xs:restriction base="xs:string" /> 
</xs:simpleType> 

<xs:simpleType name="bindingType"> 
     <xs:restriction base="xs:string" /> 
</xs:simpleType> 




<xs:complexType name="componentType"> 
    <xs:sequence>   
     <xs:element name="operation" type="operationType" /> 
     <xs:element name="event" type="eventType" /> 
    </xs:sequence> 
    <xs:attribute name="type" type="typeType"/> 
    <xs:attribute name="binding" type="bindingType"/>  
</xs:complexType> 


<xs:element name="component" type="componentType" /> 

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