views:

30

answers:

1

Hi!

Im writing a XML schema for a project. I cannot solve following problem:

A element cannot be nested by itself, ex:

<document>
   <text>
      <b>
         <i>
            <a link="http://wikipedia.org"&gt;
               <b />
            </a>
         </i>
      </b>
   </text>
</document>

This example shouldn't be allow because the b is nesting itself. So my question for you is: "Is it possible to disallow a element to nest it self, and if yes whats the procedure to do the trick?"

Thx in advantage!

\Morten Møller

Edit: Until now I only have made sure that a element can be a child of itself, but not that a element cant have a descendant that is itself.

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:xs="http://cs.au.dk/dWebTek/WikiXML"
        targetNamespace="http://cs.au.dk/dWebTek/WikiXML"
        elementFormDefault="qualified">

<element name="wiki">
    <complexType>
            <choice maxOccurs="unbounded">
                <!-- A lot of other element is listed here -->
                <element name="bold" type="xs:boldnest"/> <!-- Missing nest function -->
            </choice>
    <complexType>
</element>

<complexType name="boldnest">
    <choice maxOccurs="unbounded">
        <element name="bold" minOccurs="0" maxOccurs="0" type="xs:boldnest"/>
        <!-- All the other element is copy pasted in here -->
    </choice>
</complexType>
A: 

What you are trying to do is not possible. In XML Schema, if you are using a type-based approach, you can only control the children of an element through the content model, not all possible descendants.

The only way you could possibly get close to what you are trying to do is to fully define the contents of document down to the last level. But you cannot establish a recursive structure and then put in place the sort of constraint you are thinking of.

You will need to validate this using some other mechanism, after XML schema validation is done.

xcut