tags:

views:

17

answers:

1

Hello!

XML:

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <ac code="B2" auto="1">
        <fee>
            <if country="RU">35e 50e 50e 80e 15e 10e</if>
            <else>10e</else>
        </fee>
        <comission>
            <if country="RU">3%</if>
            <else>5%</else>
        </comission>
    </ac>
</data>

Schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

 <xs:element name="data" type="data"/>
 <xs:complexType name="data">
  <xs:sequence>
   <xs:element name="ac" minOccurs="0" maxOccurs="unbounded" type="ac"/>
  </xs:sequence>
 </xs:complexType>

 <xs:complexType name="ac">
  <xs:sequence>
   <xs:element name="fee" type="feecomiss"/>
   <xs:element name="comission" type="feecomiss"/>
  </xs:sequence>
  <xs:attribute name="code" type="xs:string"/>
  <xs:attribute name="auto" type="xs:decimal"/>
 </xs:complexType>

 <xs:complexType name="feecomiss">
  <xs:sequence>
   <xs:element name="if" minOccurs="0" maxOccurs="unbounded" type="if"/>
   <xs:element name="else" minOccurs="0" maxOccurs="unbounded" type="xs:string"/>
  </xs:sequence>
 </xs:complexType>

 <xs:complexType name="if">
   <xs:attribute name="country" type="xs:string" />
 </xs:complexType>

</xs:schema>

This scheme does not validate: (

But if i insert an element inside "if" in xml

<if country="RU"><lol>35e 50e 50e 80e 15e 10e</lol></if>

and fix schema

 <xs:complexType name="if">
  <xs:sequence>
   <xs:element name="lol" type="xs:string"/>
  </xs:sequence>
  <xs:attribute name="country" type="xs:string" />
 </xs:complexType>

That code is valid

How can I fix this?thank you!!! Sorry for bad english

+1  A: 

You need to use the <xsd:simplecontent> element here.

 <xs:complexType name="if">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="country" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
 </xs:complexType>

You can find more information on the XSD tutorial page for text-only elements. Basically what's wrong is that if isn't defined to be able to have text content because it's a complex type. You use simpleContent to allow it to contain text.

Welbog