300 likes | 642 Views
BRICS, Department of Computer Science. University of Aarhus, Denmark. 2 ... XML is successful as a machine processable data interchange format, but it is ...
E N D
xsugarDual Syntax for XML Languages Claus Brabrand Anders Møller Michael Schwartzbach {brabrand,amoeller,mis}@brics.dk BRICS, Department of Computer Science University of Aarhus, Denmark
Introduction xsugar Syntax and Semantics Unifying Syntax Tree Validation Analysis DTDs & Summary Graphs Schema Languages // Outline (3 parts) Introduction (xsugar) 1 Assessment 3 Teleportation More Examples Related & Future Work Assessment Conclusion Static Analyses 2 • Reversibility Analysis • Info Preservation • Unambiguity
Validation Analysis DTDs & Summary Graphs Schema Languages Introduction xsugar Syntax and Semantics Unifying Syntax Tree // Part 1: Introduction Introduction (xsugar) 1 Assessment 3 Teleportation More Examples Related & Future Work Assessment Conclusion Static Analyses 2 • Reversibility Analysis • Info Preservation • Unambiguity
// Motivation • Relax NG: Relax RNC Relax RNG • RNC-to-RNG: • Python script (1,478 lines) • RNG-to-RNC: • XSLT stylesheet (894 lines) Dynamic issues: • correspondence ? • maintenance ? • reversibility ? • validity (XML) ? • termination ?
// Motivation (cont’d) • XQuery: XQuery XQueryX Dynamic issues: • XQuery-to-XQueryX: • Non-existent...! • XQueryX-to-XQuery: • XSLT stylesheet (845 lines) • correspondence ? • maintenance ? • reversibility ? • validity (XML) ? • termination ?
// xsugar • One stylesheet produces: s : L X L X xsugar Static guarantees: • L2X: • Transformation: LX • X2L: • Reverse transformation: XL • correspondence ! • maintenance ! • reversibility ! • validity (XML) ! • termination !
// Example: Transformation… <student id=“19920539”> <name>Claus Brabrand</name> <email>brabrand@brics.dk</email> </student> unparsing x: transformation l : parsing Claus Brabrand (brabrand@brics.dk) 19920539 [Name n] [Email e] [Id id] Name= { ... } Email= { ... } Id= { [0-9]+ } student: [Name n] ( [Emaile] ) [Id id] \n = { <student id=[Id id]> <name><[Namen]></name> <email><[Email e]></email> </student> } s: L X parsing unparsing
// …and Reverse Transformation [Id id] [Name n] [Email e] <student id=“19920539”> <name>Claus Brabrand</name> <email>brabrand@brics.dk</email> </student> parsing x: reverse transformation l : unparsing Claus Brabrand (brabrand@brics.dk) 19920539 Name= { ... } Email= { ... } Id= { [0-9]+ } student: [Name n] ( [Emaile] ) [Id id] \n = { <student id=[Id id]> <name><[Namen]></name> <email><[Email e]></email> </student> } s: L X unparsing parsing
// Unifying Grammar student: [Name n] ( [Emaile] ) [Id id] \n = { <student id=[Idid]> <name><[Name n]></name> <email><[Emaile]></email> </student> } • N finite set of unifying nonterminals • finite alphabet of terminals • s N start unifying nonterminal • U finite set of unification names • : N P(E* E*), unifying production function, E = (N U) G = N, , s, U, unification: 2 right-hand sides
// Regular Nonterminal Shorthand Name= { ... } Email= { ... } Id= { [0-9]+ } student: [Name n] ( [Emaile] ) [Id id] \n = { ... } • Regular expressions (convenient short-hand) for regular nonterminals (w/ identity unification): Id={ [0-9]+ } desugaring id: [numn] [idi] = { <[num n]><[idi]> } : [numn] = { <[num n]> } num : 0 = { 0 } … : 9 = { 9 }
// “The Big Picture” • Reversible ? (i.e. ): • Parsing / Unparsing (i.e. ): • Grammar Ambiguity ? • Transformation (i.e. ): • Information Preservation ? UST . . . transformation transformation 1-1? 1-1? un-/parsing un-/parsing 1-1/~L? 1-1/~XML? L X ASTL / ~L ASTX / ~XML L X 1-1 . Legend: . 1-1 Canonical: l L . . Ordered tree . . Unordered tree 1-1 Partially Ordered Canonical: x X
Validation Analysis DTDs & Summary Graphs Schema Languages Introduction xsugar Syntax and Semantics Unifying Syntax Tree // Part 1: Introduction Introduction (xsugar) 1 Assessment 3 Teleportation More Examples Related & Future Work Assessment Conclusion Static Analyses 2 • Reversibility Analysis • Info Preservation • Unambiguity
Introduction xsugar Syntax and Semantics Unifying Syntax Tree Validation Analysis DTDs & Summary Graphs Schema Languages // Part 2: Static Analyses Introduction (xsugar) 1 Assessment 3 Teleportation More Examples Related & Future Work Assessment Conclusion Static Analyses 2 • Reversibility Analysis • Grammar Unambiguity • Information Preservation
// Motivating Example (Ex. cont’d) Name= { [^(\n]+ } Email= { [^,) ]+ } Id={ [0-9]+ } student: [Name n] ( [emailses] ) [Id id] \n = { <student id=[id]> <name><[n]></name> <emails><[es]></emails> </student> } emails:[Emaile]= {<email><[e]></email>} :[Emaile] , [emailses]= { <email><[e]></email> <[es]>} Anders Moeller (amoeller@brics.dk,mrmoeller@gmail.com) 19940392 <student id=“19940392”> <name>Anders Moeller</name> <emails> <email>amoeller@brics.dk</email> <email>mrmoeller@gmail.com</email> </emails> </student>
// Motivating Example (cont’d2) Name= { [^(\n]+ } Email= { [^,) ]+ } Id={ [0-9]+ } student: [Name n][opt_emailse][Id id] \n = { <student id=[id]> <name><[n]></name> <[e]> </student> } opt_emails: = {} : ( [email e] ) = {<[e]>} : ( [email e] , [emails es] ) = {<emails><[e]><[es]></emails>} emails:[emaile]= {<[e]>} :[emaile] , [emails es]= { <[e]><[es]>} email:[Emaile]= {<email><[e]></email>}
// Example (cont’d) Claus Brabrand (brabrand@brics.dk) 19920539 Anders Moeller (amoeller@brics.dk, mrmoeller@gmail.com) 19940392 Michael Schwartzbach 18791398 <student id=“19920539”> <name>Claus Brabrand</name> <email>brabrand@brics.dk</email> </student> <student id=“19940392”> <name>Anders Moeller</name> <emails> <email>amoeller@brics.dk</email> <email>mrmoeller@gmail.com</email> </emails> </student> <student id=“8”> <name>Michael Schwartzbach 1879139</name> </student>
// Example (cont’d) Claus Brabrand (brabrand@brics.dk) 19920539 Anders Moeller (amoeller@brics.dk, mrmoeller@gmail.com) 19940392 Michael Schwartzbach 18791398 <student id=“19920539”> <name>Claus Brabrand</name> <email>brabrand@brics.dk</email> </student> <student id=“19940392”> <name>Anders Moeller</name> <emails> <email>amoeller@brics.dk</email> <email>mrmoeller@gmail.com</email> </emails> </student> <student id=“8”> <name>Michael Schwartzbach 1879139</name> </student> Ambiguous grammar !
// Approximating CFG Ambiguity . • Undecidable?: • However…!: • : • Safe (over-)approximation: . ASTL / ~L L ? ambiguous unambiguous ambiguous . . unambiguous . Black-box (over-)approximation No? Yes!
// Information Preservation • “Never throw away or duplicate information”: • i.e. all named arguments must be used exactly once! UST UST . . . . L X L X ASTL / ~L ASTL / ~L
. // Reversible Stylesheets! Reversibility (proof): . . 1-1 ! 1-1 ! 1-1 ! 1-1 ! un-/parsing un-/parsing transformation transformation xsugar1-1 ! . xsugar: 1-1 ! . . L X ASTL / ~L ASTX / ~XML L X
// Validation Analysis • GivenDTD, D: l L : x(l) L(D) L(X) L(D) SG(X) L(D) Black-box “Static Validation of Dynamically Generated HTML” [ Claus Brabrand | Anders Møller | Michael Schwartzbach ] PASTE, 2001
// Summary Graphs Id={ [0-9]+ } Name= { [^(\n]+ } Email= { [^,) ]+ } student: [Name n] ( [emailses] ) [Id id] \n = { <student id=[id]> <name><[n]></name> <emails><[es]></emails> </student> } emails:[Emaile]= {<email><[e]></email>} :[Emaile] , [emails es]= { <email><[e]></email> <[es]>} [0-9]+ [^(\n]+ [^,) ]+ <student id=[]> <name><[]></name> <emails><[]></emails> </student> <email><[]></email> <email><[]></email> <[ ]> SG(X) L(D) Black-box “Static Validation of Dynamically Generated HTML” [ Claus Brabrand | Anders Møller | Michael Schwartzbach ] PASTE, 2001
Introduction xsugar Syntax and Semantics Unifying Syntax Tree Validation Analysis DTDs & Summary Graphs Schema Languages // Part 2: Static Analyses Introduction (xsugar) 1 Assessment 3 Teleportation More Examples Related & Future Work Assessment Conclusion Static Analyses 2 • Reversibility Analysis • Grammar Unambiguity • Information Preservation
Validation Analysis DTDs & Summary Graphs Schema Languages Introduction xsugar Syntax and Semantics Unifying Syntax Tree // Part 3: Assessment Introduction (xsugar) 1 Assessment 3 Teleportation More Examples Related & Future Work Assessment Conclusion Static Analyses 2 • Reversibility Analysis • Info Preservation • Unambiguity
// Related Work • “XSLT” (aka. XSL Stylesheets): • However, only one direction • “Presenting XML”: “Java web application framework for presenting HTML, PDF, WML etc., in a device independent manner”. “It aims to achieve a complete separation of content and presentation”. Relax RNC Relax RNG P1 P2
// Related Work (cont’d) • “Bi-directional Transformation Language for XML” • [Kawanaka & Hosoya] • XML <=> XML transformations: <person> <name>John Doe</name> <mail>john@doe.com</mail> <phone>01-2345-6789</phone> <phone>090-2345-6781</phone> </person> <card> <name>John Doe</name> <email>john@doe.com</email> <tel>01-2345-6789</tel> <tel>090-2345-6781</tel> </card> relation personcard = person[name[var x as String], mail[var y as String]*, phone[var z as String]*] card[name[var x as String], email[var y as String]*, tel[var z as String]*]
// Full On-line Implementation • Impementation (in Java): [ 82 K src ] • [ http://www.brics.dk/xsugar/] • Google: “xsugar” :) • On-line demo(!): • [ http://www.brics.dk/xsugar/]
// Assessment For “Relax NG”: lines Static guarantees: • correspondence ? vs ! • maintenance ? vs ! • reversibility ? vs ! • validity (XML) ? vs ! • termination ? vs ! Conciseness: [1/12+]
// Conclusion • xsugar: Reversible Stylesheets s : L X L X xsugar Static guarantees: • L2X: • Stylesheet: LX • X2L: • Reverse stylesheet: XL • correspondence ! • maintenance ! • reversibility ! • validity (XML) ! • termination !
< presentation > / Questions please…