J R o o h l a m a s o l r a C é s 2 4 0 9 / 8 2 / Constraining Content XCSL –XML Constraint Specification Language José Carlos Ramalho jcr@di.uminho.pt Contents • Behind the scene • Examples CODE • Constraint Specification Language + • System Arquitecture other inner parts • Example solutions • Future work XML Europe 2001 - 22/25 May - Berlin - Germany 2 t o ? e m u c o D L M G S G y s D n W h e r e o t e s Q u a l i : 1
J R o o h l a m a s o l r a C é s / 4 0 2 8 2 / 9 Behind the scene • SGML96 (Boston) – Semantic Validation: two approaches • SGML97 (Washington) – Where does quality go? • Markup Languages Journal – Processing constraints • Markup Technologies 98 (Chicago) – Attribute Grammar approach XML Europe 2001 - 22/25 May - Berlin - Germany 3 Behind the scene (2) • Phd thesis – 2000 – Low-level functional approach – Formal specification of XCSL: • Attribute grammar • XAM specification – Processor: had to be written in the host functional language (SSL, Haskell) • Desired goal – To have everything in the same declarative paradigm XML Europe 2001 - 22/25 May - Berlin - Germany 4 D m : s t n e u W c o D L M G S h o i e s Q u a l t r y G o ? e e 2
J o h l a m a R o s l r a C é s o 2 4 0 / 2 / 9 8 Motivation • To meet some particular project needs • Sometimes we do not want a Schema or a DTD – We just want to constraint certain document parts • Requirements: – The solution should work with existing tools and standards – The solution should work across every platform XML Europe 2001 - 22/25 May - Berlin - Germany 5 Type inference Problem: how to process ... ? Constraint: latitude > 39 and latitude < 42.5 Document: ...<latitude>41.32</latitude>... Answer: ...<latitude type=“float”>41.32</latitude>... Can be transparent to users: #FIXED attributes XML Europe 2001 - 22/25 May - Berlin - Germany 6 r u : s t n e m o c W D L M G S e e u D o e s Q a l i t y G o ? h 3
J R o o h l a m a s o l r a C é s 2 4 0 / / 8 2 9 Value normalization Problem: How can I identify ...? ... King <name>Affonso</name> proclaimed several ... ... And his soldiers battled against <name>Afonso</name>. ...and that church was built in the <date>XVIII century</date>. ...it all happened on <date> the fifth October</date>... Answer ...King <name value=“Afonso”>Affonso</name>... ...it all happened on <date value=“xxxx.10.05”>the fifth... User awareness is needed! XML Europe 2001 - 22/25 May - Berlin - Germany 7 Programs ⇔ XML Documents • Have a support • Have a support markup language formally language defined in defined XML • Processing - compiler • Processing - parser – lexical analysis – lexical analysis – syntactic analysis – syntactic analysis – semantic analysis – semantic analysis • complex: type checking; • very simple: ID - IDREF type inference, ... coupling • Can be formally specified: Attribute Grammars XML Europe 2001 - 22/25 May - Berlin - Germany 8 L m S : s t n e u G M c o D t h W u G o ? i l a Q y e o D e r e s 4
J R o o h l a m a s o l r a C é s 2 4 0 2 / 8 9 / Constraints: what type? i. Domain range checking • Normally data is of type numeric or date ii. Dependencies between two elements or attributes iii. Pattern matching against a Regular Expression • Enforcing content to follow a certain format • Example: [0-9]{4}\.[0-9]{2}\.[0-9]{2} iv. Quantified constraints … (???) XML Europe 2001 - 22/25 May - Berlin - Germany 9 Example1: students <?xml version="1.0"?> We want: <students> • to ensure that each grade is greater <student> <name>Peter Weird</name> than 10 <grades> • to give a warning message for each <grade1>12</grade1> <grade2>8</grade2> grade below 10 <grade3>15</grade3> </grades> </student> <student> <name>Jose Almeida</name> <grades> <grade1>9</grade1> <grade2>18</grade2> <grade3>7</grade3> </grades> domain range (i) </student> </students> XML Europe 2001 - 22/25 May - Berlin - Germany 10 a m : s t n e c u W o D L M G S e h u o G y t i l Q ? s e o D e r 5
J o o h l a m a R s o l r a C é s 4 0 2 / 8 2 / 9 Example2: linguistics <?xml version="1.0"?> <doc> <sentence> <noun number="s" genre="f">Alice</noun> <verb time="present" number="s“ person="3">drinks</verb> </sentence> <sentence> <noun number="p">Dogs</noun> <verb time="present" number="s" person="3">barks</verb> </sentence> <sentence> <noun genre="f" number="s">Diana</noun> <verb number="s">are</verb> In portuguese: <adj genre="m" number="s">beautiful</adj> </sentence> • verbs must agree with correspondent nouns in </doc> person and number • adjectives must agree with correspondent nouns in genre and number XML Europe 2001 - 22/25 May - Berlin - Germany 11 Example3: XDBML <DATA> <items> <?xml version="1.0"?> <items-REG> <DB> <code>a111</code> <STRUCTURE> <description>leite agros meio-gordo</description> <TABLE NAME="items"> </items-REG> <COLUMNS> <items-REG> <COLUMN NAME="code" TYPE="nvarchar" SIZE="10" NULL="no"/> <code>a115</code> <COLUMN NAME="description" TYPE="nvarchar" SIZE="50" NULL="no"/> <description>leite agros chocolatado</description> ... </items-REG> </COLUMNS> <items-REG> <KEYS> <code>a112</code> <PKEYS TYPE="simple"> <description>leite agros meio-gordo</description> <PKEY NAME="code"/> </items-REG> </PKEYS> <items-REG> </KEYS> <code>a115</code> </TABLE> <description>leite agros chocolatado</description> </STRUCTURE> </items-REG> ... </DATA> </DB> XML Europe 2001 - 22/25 May - Berlin - Germany 12 m W : s t n e ? u h o D L M G S c r e a o G y t i l u e Q s e o D 6
J R o o h l a m a s o l r a C é s / 4 0 2 8 2 / 9 XDBML(2): the problem RDB RDB’ XML XML’ document document f XML Europe 2001 - 22/25 May - Berlin - Germany 13 XDBML(2): the problem • We want to transform the database in the XML axis (with XSLT). • We want to upload the new database into a DBMS • We must ensure: – Primary keys are still primary keys (challenging) – ID/IDREF attributes are globally unique – Other constraints are easy to deal with • Do we need quantifiers? – For each key, test if its value is unique. – Are quantifiers already there? XML Europe 2001 - 22/25 May - Berlin - Germany 14 m : s t n e u W c o D L M G S h D l o e s Q u a i r t y G o ? e e 7
J R o h l a m a s o l r a C é s o 2 4 0 2 / / 9 8 Constraint Spec. Lang. • From author’s Phd – Subset of XSLT – Composition: set of triples ConstraintSpec = Constraint+ Constraint = (ContextSelector,ContextCondition,Action) We can use a XSLT processor to handle Const.Processing Xpath ?? code XPath predicates XML Europe 2001 - 22/25 May - Berlin - Germany 15 Architecture XML Constraint Constraint Spec. Processor Generator XML XSL stylesheet Standard XSL XML Processor XML instance Error Messages...? XML Europe 2001 - 22/25 May - Berlin - Germany 16 u c o D L M G S e m n W Q h e r e : D o e s u t a l i t y G o ? s 8
J R o o h l a m a s o l r a C é s / 4 2 0 8 9 / 2 CSL with a XML wrapper DTD: V1.0 <!ELEMENT cs (constraint)+> <!ELEMENT constraint (selector,cc,action)> <!ELEMENT selector EMPTY> <!ELEMENT cc EMPTY> <!ELEMENT action (message*)> <!ELEMENT message (#PCDATA|value)*> <!ELEMENT value EMPTY> <!ATTLIST cs dtd CDATA #IMPLIED date CDATA #IMPLIED version CDATA #IMPLIED > <!ATTLIST selector selexp CDATA #REQUIRED> • action is a message list <!ATTLIST cc cond CDATA #REQUIRED> • value is used to refer document nodes inside messages <!ATTLIST value selexp CDATA #REQUIRED> XML Europe 2001 - 22/25 May - Berlin - Germany 17 XCSL1: Students <?xml version="1.0"?> <CS> <CONSTRAINT> <SELECTOR SELEXP="//student/grades/*"/> <CC>.>10</CC> <ACTION> <MESSAGE>WARNING: <VALUE SELEXP="name(.)"/> of <VALUE SELEXP="../../name"/> is below minimum!</MESSAGE> </ACTION> </CONSTRAINT> </CS> Spotting grades lower than 10. XML Europe 2001 - 22/25 May - Berlin - Germany 18 m : s t n e u W c o D L M G S h ? a o G y t i l u e Q s e o D e r 9
Recommend
More recommend