160 likes | 303 Views
XML XPath Formal Semantics. XPath Type System Pontikakis Emmanuel. XPath Basics. Expressions (Queries) /books/book/author/lastname /books/book/author[address]/firstname //book[ISBN]/author. XPath Basics. XPath Processing Model. Parsing. (Step SQ 1 ) Static Context p rocessing.
E N D
XML XPath Formal Semantics XPath Type System Pontikakis Emmanuel
XPath Basics • Expressions (Queries) /books/book/author/lastname /books/book/author[address]/firstname //book[ISBN]/author CS 203 - Fall 2004
XPath Basics CS 203 - Fall 2004
XPath Processing Model • Parsing. • (Step SQ1) • Static Context processing. • (Steps SQ2, SQ3,SQ4) • Normalization. • (Step SQ5) • 4. Static type analysis.(Step SQ6) • Dynamic Context processing. • (Steps DQ2, DQ3) • 6. Dynamic Evaluation. (Steps DQ4, DQ5) CS 203 - Fall 2004
Why Formal Semantics? • A reference for implementation, interoperability • Rigor definitions of the Language characteristics • Exact definition of relations between objects (types, elements, attributes, etc.) CS 203 - Fall 2004
Semantics • Static Semantics are used to infer the type of an expression or raise an error, if there is a mismatch • Dynamic Semantics are used to map XPath expressions to the value they evaluate CS 203 - Fall 2004
XML Schema and Type System • The relation between XML Schema and the formal XPath type system is given shortly by the following rules: • Formal Semantics uses formal notations for types instead of XML Schema syntax. • Formal notations are not exposed to the user. • All anonymous types are made explicit for the clarification of the semantics. • XML Schema identity constraints are not formally represented in the XPath type system. CS 203 - Fall 2004
Normalization element(ElementName, TypeName) == element ElementName of type TypeName Examples: 1. element address of type xs:string { “100 Mission Str." } 2. element title of type xs:string, element year of type xs:integer CS 203 - Fall 2004
The union of two element types • The "|" operator builds the "union" of two types. For example: element editor of type xs:string | element bib:author CS 203 - Fall 2004
Interleaved product of types The "&" operator builds the "interleaved product" of two types. For example: (element a & element b) = element a, element b | element b, element a which specifies that the a and b elements can occur in any order. CS 203 - Fall 2004
Type Derivation statEnv |- TypeName1derives fromTypeName2 Derivation is transitive. statEnv |- TypeName1 derives fromTypeName2 statEnv |- TypeName2 derives fromTypeName3 _______________________________________ statEnv |- TypeName1 derives fromTypeName3 CS 203 - Fall 2004
Type Substitution statEnv |- TypeName1substitutes forTypeName2 Substitution is transitive. statEnv |- TypeName1 substitutes forTypeName2 statEnv |- TypeName2 substitutes forTypeName3 _______________________________________ statEnv |- TypeName1 substitutes forTypeName3 CS 203 - Fall 2004
Type matching statEnv |- ValuematchesType element comment of type xsd:string { "This is a string" } matches element comment of type xsd:string Example: statEnv |- Value1 matchesType1 statEnv |- Value2 matchesType2 _______________________________________ statEnv |- Value1,Value2 matchesType1,Type2 CS 203 - Fall 2004
Schema Definition • A type declaration with complex content: XML Schema: <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> CS 203 - Fall 2004
Type Definition define type PurchaseOrderType { attribute orderDate of type xsd:date?, element shipTo of type USAddress, element billTo of type USAddress, element items of type Items } CS 203 - Fall 2004
ευχαριστώ! CS 203 - Fall 2004