[dsdl-comment] Re: Need help understanding triggers

From: Costello, Roger L. <costello@mitre.org>
Date: Wed May 28 2008 - 13:30:06 UTC

Thank you very much Murata-san. That fixed it. Now I understand how
triggers work.
 
Below is a working example that illustrates the use of triggers.
 
The purpose of triggers: sometimes you want to perform a finer level of
processing than "process uniformly everything in this namespace." With
triggers, what would ordinarily be one section, can be decomposed into
several parts.
 
This Book is comprised of one namespace (thus, one section):
 
-----------------------------------------------------
Book.xml
-----------------------------------------------------
<?xml version="1.0"?>
<Book xmlns="http://www.book.org
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.book.or
g/> ">
    <Title>The Wisdom of Crowds</Title>
    <Author>James Surowiecki</Author>
    <Date>2005</Date>
    <ISBN>0-385-72170-6</ISBN>
    <Publisher>Anchor Books</Publisher>
</Book>
 
There is a schema, Book.rng, which can be used to validate this
section. (The schema is below). The schema declares all the leaf nodes
to be of the string data type.
 
There is another schema, Publisher.xsd, which restricts the <Publisher>
element to a small set of values. And this schema is for the same
namespace. (This schema is also shown below)
 
I want to decompose the Book section using a trigger. For the
<Publisher> element I want it validated using Publisher.xsd, and the
rest of the Book section validated using Book.rng.
 
Below is the NVDL to accomplish this.
 
-----------------------------------------------------
Book.nvdl
-----------------------------------------------------
<?xml version="1.0"?>
<rules startMode="book"
           xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://purl.oclc.o
rg/dsdl/nvdl/ns/structure/1.0> ">
   <trigger ns="http://www.book.org
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.book.or
g> "
                nameList="Publisher" />
   <mode name="book">
       <namespace ns="http://www.book.org
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.book.or
g> ">
           <validate schema="Book.rng"
                          useMode="publisher" />
       </namespace>
   </mode>
   <mode name="publisher">
       <namespace ns="http://www.book.org
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.book.or
g> ">
           <validate schema="Publisher.xsd"/>
           <attach />
       </namespace>
   </mode>
</rules>

-----------------------------------------------------
Book.rng
-----------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<element name="Book"
               xmlns="http://relaxng.org/ns/structure/1.0
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://relaxng.org
/ns/structure/1.0> "
               ns="http://www.book.org
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.book.or
g> ">
      <element name="Title">
          <text/>
      </element>
      <element name="Author">
          <text/>
      </element>
      <element name="Date">
          <text/>
      </element>
      <element name="ISBN">
          <text/>
      </element>
      <element name="Publisher">
          <text/>
      </element>
</element>
 
-----------------------------------------------------
Publisher.xsd
-----------------------------------------------------
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.w3.org/
2001/XMLSchema> "
              targetNamespace="http://www.book.org
<https://webmail.mitre.org/exchweb/bin/redir.asp?URL=http://www.book.or
g> "
              elementFormDefault="qualified">
 
    <element name="Publisher">
        <simpleType>
            <restriction base="string">
                <enumeration value="Anchor Books"/>
            </restriction>
        </simpleType>
    </element>
 
</schema>

--
DSDL comments
To unsubscribe, please send a message with the
command  "unsubscribe" to dsdl-comment-request@dsdl.org
(mailto:dsdl-comment-request@dsdl.org?Subject=unsubscribe)
Received on Wed May 28 15:30:12 2008

This archive was generated by hypermail 2.1.8 : Thu May 29 2008 - 18:53:07 UTC