2012-01-10 16 views
8

Verilen:Yalnızca XML şemasındaki özelliklerle bir öğe nasıl bildirilir?

<authentication password="turkey" partnerid="exam" /> 

nasıl bir XML şemasında bu eleman ilan edebilir? o olacak

<xs:element name="authentication" type="auth_type" /> 

<xs:complexType name ="auth_type"> 
    <xs:simpleContent> 
    <xs:extension base="xs:string"> 
     <xs:attribute name="password" type="xs:string" /> 
     <xs:attribute name="partnerid" type="xs:string" /> 
    </xs:extension> 
    </xs:simpleContent> 
</xs:complexType> 

ama eleman metin içeriğine sahip sağlayacak:

ben var? Ben bunu istemiyorum ...

cevap

15

Sen kaldırabilirsiniz xs:simpleContent ve xs:extension ....

<xs:element name="authentication" type="auth_type" /> 

    <xs:complexType name ="auth_type"> 
    <xs:attribute name="password" type="xs:string" /> 
    <xs:attribute name="partnerid" type="xs:string" /> 
    </xs:complexType> 
+0

<xs:element name="product"> <xs:complexType> <xs:complexContent> <xs:restriction base="xs:integer"> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:restriction> </xs:complexContent> </xs:complexType> </xs:element> 

kontrolü: uzantısı oldu Bir öğenin özniteliklere sahip olmasına izin vermek için ... – Mirko

+0

@Mirko - Örneğinizde 'xs: simpleContent 've' xs: simpleContent' öğelerini genişletmek için 'xs: extension' kullanmanız gerekiyordu. –

0

ne lüzum örneğin karmaşık bir elementtir:

<product prodid="1345" /> 

" Yukarıdaki "ürün" öğesinde hiç içerik yok. içeriksiz bir türünü tanımlamak için, içeriğindeki unsurları sağlayan bir türünü tanımlamak gerekir, ama aslında bu gibi herhangi unsurları beyan yoktur: Ben xs düşünce http://www.w3schools.com/schema/schema_complex_empty.asp

İlgili konular