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

  • From: Rick Jelliffe <ricko@a...>
  • To: xml-dev@l...
  • Date: Thu, 30 Aug 2001 15:25:05 +1000

There is no way to determine the root element of a document from
a W3C XML Schema schema.

Any element definition in an XML schema (not being a local one) 
could be used as the top level of an element (or the top-level of 
a branch of that namespace.)

You can find possible tops of branches.  But wildcards and other recursion
needed to be coped with too.

If you want to specify the root element of a document, you can use a 
Schematron schema like the following:
<schema xmlns="http://www.ascc.net/xml/schematron" >
     <pattern>
          <rule context = "/*">
               <assert test = "/myelement">Root element should be "myelement".</assert>
          </rule>
     </pattern>
</schema>

You can also specify that some elements may not appear except as children
of the same namespace.

     <pattern>
          <rule context = "ns1:e1 | ns1:e2 | ns1:e3 ">
               <assert test = "../ns1:*">e1, e2, and e3 must appear as children of 
              an element in the same namespace.</assert>
          </rule>
     </pattern>

Cheers
Rick Jelliffe


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