Download presentation
Presentation is loading. Please wait.
Published byEthel Simon Modified over 9 years ago
1
Structured-Document Processing Languages Spring 2011 Course Review Repetitio mater studiorum est!
2
SDPL 2011Course Review2 Goals of the Course n Learn about central models and languages for –manipulating –transforming and –querying structured documents (or XML) n "Generic XML processing technology"
3
SDPL 2011Course Review3 XML? n Extensible Markup Language is not a markup language! –does not fix a tag set nor its semantics (like markup languages like HTML do) n XML is –A way to use markup to represent information –A metalanguage »supports definition of specific markup languages through XML DTDs or Schemas »E.g. XHTML a reformulation of HTML using XML
4
SDPL 2011Course Review4 XML Encoding of Structure: Example <S> S E <W></W> Hithere! W Hi Hi W there! </W> </S> b=2A=1
5
SDPL 2011Course Review5 Basics of XML DTDs n A Document Type Declaration provides a grammar (document type definition, DTD) for a class of documents Syntax (in the prolog of document instance): [ ]> Syntax (in the prolog of document instance): [ ]> n DTD = union of the external and internal subset
6
SDPL 2011Course Review6 Example DTD <!ATTLIST item price NMTOKEN #REQUIRED unit (FIM | EUR) ”EUR” >
7
Lang/Model Purpose Structure of Processing (i) docs model (i) docs model (ii) model (ii) model SDPL 2011Course Review7 Review
8
SDPL 2011Course Review8 XML Namespaces </xsl:template></xsl:stylesheet>
9
SDPL 2011Course Review9 3. XML Processor APIs n How can applications manipulate structured (XML) documents? –An overview of XML processor interfaces 3.1 SAX: an event-based interface 3.2 DOM: an object-based interface 3.3 JAXP: Java API for XML Processing 3.4 StAX: Streaming API for XML
10
SDPL 2011Course Review10 A SAX-based application Application Main Routine startDocument() startElement() characters() parse() Callback Routines endElement() </A>Hi! "A",[i="1"] "Hi!" "A"
11
SDPL 201111Course Review
12
Lang/Model Purpose Structure of Processing (i) docs model (i) docs model (ii) model (ii) model SDPL 2011Course Review12 Review
13
SDPL 2011Course Review13 3.4 Streaming API for XML (StAX) n Event-driven streaming API, like SAX n "Pull API" –lets the application to ask for individual events n Two sets of APIs: –"cursor" (XMLStreamReader), and "iterator" (XMLEventReader) n Bidirectional: –XMLStreamWriter or XMLEventWriter support "marshaling" data into XML
14
SDPL 2011Course Review A Pull-Parsing Application ApplicationEventReader.nextEvent() Parser API StartDocument Hi! Characters"Hi!" </A> EndElement"A" StartElement "A",[i="1"] 14
15
SDPL 2011Course Review15 DOM: What is it? n Object-based, language-neutral API for XML and HTML documents –Allows programs/scripts to »build »navigate and »modify documents n “Directly Obtainable in Memory” vs “Serial Access XML”
16
SDPL 2011Course Review16 <invoice form="00" type="estimated"> type="estimated"> John Doe John Doe Pyynpolku 1 Pyynpolku 1 70460 KUOPIO 70460 KUOPIO...... DOM structure model invoice name addressdata address form="00"type="estimated" John Doe streetaddresspostoffice 70460 KUOPIO Pyynpolku 1... Document Element NamedNodeMap Text
17
SDPL 201117Course Review
18
Lang/Model Purpose Structure of Processing (i) docs model (i) docs model (ii) model (ii) model SDPL 2011Course Review18 Review
19
SDPL 2011Course Review19 XSLT Transformations
20
Lang/Model Purpose Structure of Processing (i) docs model (i) docs model (ii) model (ii) model SDPL 2011Course Review20 Review
21
SDPL 2011Course Review21 JAXP (Java API for XML Processing) n Interface for “plugging-in” and using XML processors in standard Java applications –org.xml.sax: SAX 2.0 –javax.xml.stream : StAX –org.w3c.dom: DOM Level 2 (+ Level 3 Core) –javax.xml.parsers: initialization and use of parsers –javax.xml.transform: initialization and use of XSLT transformers
22
SDPL 2011Course Review22 XML.getXMLReader() JAXP: Using a SAX parser (1) f.xml.parse( ”f.xml”) ”f.xml”).newSAXParser()
23
SDPL 2011Course Review23 f.xml JAXP: Using a DOM parser (1).parse(”f.xml”).newDocument().newDocumentBuilder()
24
SDPL 2011Course Review24 XSLT JAXP: Using Transformers (1).newTransformer(…).transform(.,.)
25
Lang/Model Purpose Structure of Processing (i) docs model (i) docs model (ii) model (ii) model SDPL 2011Course Review25 Review
26
SDPL 2011Course Review26 W3C XQuery n Functional expression language –A query is a side-effect-free expression n Operates on sequences of items –XML nodes or atomic values Strongly-typed: (XML Schema) types may be assigned to expressions statically, and results can be validated Strongly-typed: (XML Schema) types may be assigned to expressions statically, and results can be validated n Extends XPath 2.0 ( but not all axes required) –common for XQuery 1.0 and XPath 2.0: »Functions and Operators, W3C Rec. 01/2007 n Roughly: XQuery XPath 2.0 + XSLT' + SQL'
27
SDPL 2011Course Review27 FLWOR ("flower") Expressions n for, let, where, order by and return clauses (~SQL select-from-where) n Form: (ForClause | LetClause)+ WhereClause? OrderByClause? "return" Expr n binds variables to values, and uses these bindings to construct a result (an ordered sequence of items)
28
SDPL 2011Course Review28 XQuery Example for $pn in distinct-values( doc(”sp.xml”)//pno) let $sp:=doc(”sp.xml”)//sp_tuple[pno=$pn] where count($sp) >= 3 order by $pn return {$pn} {$pn} {avg($sp/price)} {avg($sp/price)}
29
Lang/Model Purpose Structure of Processing (i) docs model (i) docs model (ii) model (ii) model SDPL 2011Course Review29 Review
30
SDPL 2011Course Review30 Course Main Message n XML is a universal way to represent information as tree-like data structures n There are specialized and powerful technologies for processing it –hype has settled –R&D still going on
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.