[Home] [By Thread] [By Date] [Recent Entries]

  • From: Mukul Gandhi <mukulg@s...>
  • To: Roger L Costello <costello@m...>
  • Date: Tue, 25 Jan 2022 18:23:40 +0530

Hi Roger,
    How about following approach.

The XML instance document is like following,

<?xml version="1.0"?>
<Publication>
   <Title>abc</Title>
   <ISBN>123-456-789</ISBN>
</Publication>

And with the following XML Schema 1.1 document,

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
  <xs:element name="Publication">
     <xs:complexType>
       <xs:all>
          <xs:element name="Title" type="xs:string"/>
          <xs:any processContents="skip" minOccurs="0"/>
       </xs:all>
       <xs:assert test="if (*[not(self::Title)]) then *[not(self::Title)][count(node()) = 1 and text()] else true()"/>
       <xs:assert test="if (*[not(self::Title)]) then not(*[not(self::Title)]/@*) else true()"/>
       <xs:assert test="if (*[not(self::Title)]) then (*[not(self::Title)]/name() = ('ISBN','Edition')) else true()"/>
     </xs:complexType>
  </xs:element>
 
</xs:schema>

I meant following with the above cited schema document,
The Title element can have an optional sibling element, and its name be either ISBN or Edition. That sibling element, cannot have non text child, and it cannot have attributes as well.

I guess, above schema document is not a great alternative, to solutions already proposed. But just another solution :)

On Mon, Jan 24, 2022 at 4:24 AM Roger L Costello <costello@m...> wrote:

You are correct that for this example it is possible to factor out the declaration of the Title element. But there are examples where this is not possible, such as this:

 

<xs:choice>
    <xs:sequence>
        <xs:element name="ISBN" minOccurs="0" type="xs:string"/>
        <xs:element name="Title" type="xs:string"/>
    </xs:sequence>
    <xs:sequence>
        <xs:element name="Title" type="xs:string"/>
        <xs:element name="Edition" type="xs:string"/>
    </xs:sequence>
</xs:choice>

 

Notice that the ISBN element is optional, so we get the dreaded “Unique Particle Attribution” error.


 

--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member