1 / 16

Example 23

Example 23. <Document xmlns="http://www.example.org"> <What taxonomy=" http://www.dmoz.org/Society/Book/Philosophy/ " /> <Payload> <Book xmlns="http://www.book.org"> <Title>The First and Last Freedom</Title> <Author>J. Krishnamurti</Author>

ruana
Télécharger la présentation

Example 23

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example 23

  2. <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/Society/Book/Philosophy/" /> <Payload> <Book xmlns="http://www.book.org"> <Title>The First and Last Freedom</Title> <Author>J. Krishnamurti</Author> <Date>1954</Date> <ISBN>0-06-064831-7</ISBN> <Publisher>Harper &amp; Row</Publisher> </Book> </Payload> </Document> Constraint Between Components • Consider an XML instance document that has two parts: • The "what" part describes - using a standard taxonomy - what's in the • other part. • 2. The "payload" part contains a data component. • EXAMPLE #1 • The "what" part uses the DMOZ taxonomy to provide the hierarchy for a • philosophy book. The "payload" part contains data on a philosophy book.

  3. Constraint Between Components EXAMPLE #2 The "what" part uses the DMOZ taxonomy to provide the hierarchy for the Chinese language. The "payload" part contains data on the Chinese language. <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese> </Payload> </Document>

  4. Constraint Between Components PROBLEM How do you create an NVDL script which will validate that: If the value of the taxonomy attribute is http://www.dmoz.org/Society/Book/Philosophy/ then validate the data component in <StructuredPayload> against:     the Book schema If the value of the taxonomy attribute is http://www.dmoz.org/World/Language/Chinese/ then validate the data component in <StructuredPayload> against:     the Chinese schema Further ... the data components in <StructuredPayload> may be expressed in any schema language (XML Schema, Relax NG, DTD, Schematron). How would you create an NVDL script to do this?

  5. <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese> </Payload> </Document> An NVDL Processor Divides the Instance into Sections <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> </Payload> </Document> N V D L processor <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese>

  6. <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese> </Payload> </Document> … and then Validates each Section Document.xsd Validate <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> </Payload> </Document> N V D L processor <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese> Chinese.xsd

  7. <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese> </Payload> </Document> <Document xmlns="http://www.example.org"> <What taxonomy="http://www.dmoz.org/World/Language/Chinese/" /> <Payload> </Payload> </Document> N V D L processor How do we express the constraint between the taxonomy value and the payload value? <Chinese xmlns="http://www.chinese.org"> <Pronouns> <Spoken>Ta</Spoken> </Pronouns> </Chinese>

  8. Acknowledgement • Thanks to George Cristian Bina for explaining to me how to solve this problem (see the following slides for the solution). Thanks George!

  9. Solution • Validate each section independently • Validate the Document section against Document.xsd • Validate the payload section against it's schema • Validate a Book section against Book.xsd • Validate a Chinese section against Chinese.xsd • Attach the payload section to its parent (Document) section and then use Schematron to validate the relationship between the taxonomy and the payload

  10. NVDL Script <?xml version="1.0" encoding="UTF-8"?> <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="example"> <mode name="example"> <namespace ns="http://www.example.org"> <validate schema="Document.xsd" useMode="content"/> <validate schema="rules.sch"> <mode> <anyNamespace> <attach/> </anyNamespace> </mode> </validate> </namespace> </mode> <mode name="content"> <namespace ns="http://www.book.org"> <validate schema="book.xsd"/> </namespace> <namespace ns="http://www.chinese.org"> <validate schema="chinese.xsd"/> </namespace> </mode> </rules> See following slides for an explanation 

  11. <?xml version="1.0" encoding="UTF-8"?> <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="example"> <mode name="example"> <namespace ns="http://www.example.org"> <validate schema="Document.xsd" useMode="content"/> <validate schema="rules.sch"> <mode> <anyNamespace> <attach/> </anyNamespace> </mode> </validate> </namespace> </mode> <mode name="content"> <namespace ns="http://www.book.org"> <validate schema="book.xsd"/> </namespace> <namespace ns="http://www.chinese.org"> <validate schema="chinese.xsd"/> </namespace> </mode> </rules> Validate the Document section against Document.xsd and then for the child (payload) section switch to the content mode.

  12. <?xml version="1.0" encoding="UTF-8"?> <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="example"> <mode name="example"> <namespace ns="http://www.example.org"> <validate schema="Document.xsd" useMode="content"/> <validate schema="rules.sch"> <mode> <anyNamespace> <attach/> </anyNamespace> </mode> </validate> </namespace> </mode> <mode name="content"> <namespace ns="http://www.book.org"> <validate schema="book.xsd"/> </namespace> <namespace ns="http://www.chinese.org"> <validate schema="chinese.xsd"/> </namespace> </mode> </rules> Validate a www.book.org payload against book.xsd and a www.chinese.org payload against chinese.xsd

  13. <?xml version="1.0" encoding="UTF-8"?> <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="example"> <mode name="example"> <namespace ns="http://www.example.org"> <validate schema="Document.xsd" useMode="content"/> <validate schema="rules.sch"> <mode> <anyNamespace> <attach/> </anyNamespace> </mode> </validate> </namespace> </mode> <mode name="content"> <namespace ns="http://www.book.org"> <validate schema="book.xsd"/> </namespace> <namespace ns="http://www.chinese.org"> <validate schema="chinese.xsd"/> </namespace> </mode> </rules> Attach any child sections of www.example.org to its parent, and then use a Schematron schema to validate constraints between the sections.

  14. Schematron expresses the constraint between the taxonomy value and the payload <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.ascc.net/xml/schematron"> <ns uri="http://www.example.org" prefix="ex"/> <ns uri="http://www.chinese.org" prefix="ch"/> <ns uri="http://www.book.org" prefix="bk"/> <pattern name="checkTaxonomyPayloadMatch"> <rule context="ex:Document[ex:What/@taxonomy='http://www.dmoz.org/World/Language/Chinese/']"> <assert test="ex:Payload/*[namespace-uri()='http://www.chinese.org']"> When taxonomy is http://www.dmoz.org/World/Language/Chinese/ the Payload should contain content from the http://www.chinese.org namespace </assert> </rule> <rule context="ex:Document[ex:What/@taxonomy='http://www.dmoz.org/Society/Book/Philosophy/']"> <assert test="ex:Payload/*[namespace-uri()='http://www.book.org']"> When taxonomy is http://www.dmoz.org/Society/Book/Philosophy/ the Payload should contain content from the http://www.book.org namespace </assert> </rule> </pattern> </schema>

  15. Implementation • See the folder example23 for the NVDL script, the schemas, and actual XML instances.

  16. Validating Constraints Across Components • This example has shown how to express constraints across components • Furthermore, the components can be expressed in different schema languages. Relax NG Wow! DTD Schematron XML Schema

More Related