Subject: [CODE4LIB] XML schemas question

From: Jonathan Rochkind <[email-masked]>
Date: Mon, 27 Jul 2009 11:35:09 -0400

Anyone familiar with XML schemas (.xsd)?

Can you help me figure something out. Is there something in the schema 
that specifies what elements can serve as the 'root node'... or is any 
element described in the schema avaialable for use as a 'root node', and 
it'll still validate?

Thanks for any tips.

Jonathan

---

From: "Ray Denenberg, Library of Congress" <[email-masked]>
Date: Mon, 27 Jul 2009 11:48:18 -0400

Any element that is not a child of another.   Or another way to look at it, 
any element that can be referenced by "ref=".

In the following schema:

______________________________________________
<xs:schema>
<xs:element name="a" type="aType"/>
<xs:element name="b" type="bType"/>
<!-- !-->
<xs:complexType name="aType">
<xs:element ref="a"/>
<xs:element name="c" type="xs:string"/>
</xs:complexType>
<!-- !-->
<xs:complexType name="bType">
<xs:element ref="b"/>
<xs:element name="c" type="xs:string"/>
</xs:complexType>
</xs:schema>
__________________________________________________________

<a>,  and <b> can be roots.  <d> cannot.

--Ray

---

From: "Houghton,Andrew" <[email-masked]>
Date: Mon, 27 Jul 2009 11:51:33 -0400

> -----Original Message-----
> From: Code for Libraries [mailto:[email-masked]] On Behalf Of
> Jonathan Rochkind
> To: [email-masked]
> element described in the schema available for use as a 'root node',
> and
> it'll still validate?

Any global element is available as a document element in an instance
document.  Typically, you can use global types, specify one global
element and use the Russian Doll approach to limit which elements
can be used for the document element in an instance document.  The
upside is that you can control what elements are used for instance
documents.  The downside is that schema reuse drops because inner
elements cannot be reused in other contexts.

Andy.

---

From: Casey A Mullin <[email-masked]>
Date: Mon, 27 Jul 2009 08:54:20 -0700

Based on schema logic, and at first blush, I think your second assertion 
is correct. A schema specifies what specific elements must contain, but 
not which elements must contain THEM. In other words, the schema 
validator looks down the tree, but not up or across the tree.

As a quick and dirty test, I created the following schema in oXygen:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="child" minOccurs="1"/>
            <xs:element ref="child2" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
   
<xs:element name="child"/>
<xs:element name="child2"/>
   
</xs:schema>

Then, I created the following instance document:

<?xml version="1.0" encoding="UTF-8"?>
<child xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
xsi:noNamespaceSchemaLocation="file:/C:/Documents%20and%20Settings/cmullin/My%20Documents/text.xsd"/>

Though the "root" element of my instance document (<child>) is defined 
as a required child element of <root>, there are no "down-tree" 
requirements for <child>. Thus, the document is valid with only <child>.

Bear in mind that this experiment was based on only the simplest of 
examples. Is there something I'm missing? I look forward to other 
responses...

Hope this has helped,
Casey

Jonathan Rochkind wrote:
> element described in the schema avaialable for use as a 'root node', 
> and it'll still validate?
>
> Thanks for any tips.
>
> Jonathan

-- 
Casey A. Mullin
Discovery Metadata Librarian
Metadata Development Unit
Stanford University Libraries
650-736-0849 
[email-masked]
http://www.caseymullin.com

---

From: ajs6f <[email-masked]>
Date: Mon, 27 Jul 2009 11:55:38 -0400

A good brief discussion of the issues:

http://www.xfront.com/GlobalVersusLocal.pdf

---
A. Soroka
Digital Research and Scholarship R & D
the University of Virginia Library

On Jul 27, 2009, at 11:51 AM, Houghton,Andrew wrote:
>> From:  On Behalf Of Jonathan Rochkind