Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 1 Agenda Introduction - "Why XML?" Section 1: XML Basics Section.

Similar presentations


Presentation on theme: "XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 1 Agenda Introduction - "Why XML?" Section 1: XML Basics Section."— Presentation transcript:

1 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 1 Agenda Introduction - "Why XML?" Section 1: XML Basics Section 2: Parsers and SAX and DOM (oh, my!) Section 3: XPath and XSLT Section 4: SOAP and WebServices Questions, Answers, and Evasions

2 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 2 Role of the Parser The parser does the “grunt work” of deconstructing the XML. Calling code communicates with the parser via an API (Application Program Interface).

3 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 3 Two Main Types of Parser APIs Event-Driven: (SAX, SAX2, etc.) - Callback-functions for generic events, like: "Start Element" "End Element" "Received Character Data" (etc..) - Fast. Small memory footprint. - Caller responsible for a lot of work. Tree-Based: (DOM, JDOM, etc.) - Entire document is loaded into memory at once, and traversed via specialized methods (getChildNodes()) or via XPath. - Slower and more resource-intensive than SAX, - Easier to use in most cases.

4 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 4 Aside: Callback Functions Callbacks are “reminders” that are passed from function A to function B, that tell B to call A when the right conditions occur. Unfortunately, in languages like C and C++, the syntax of callbacks can look very scary: typedef void (*XML_StartElementHandler)( void *userData, const XML_Char *name, const XML_Char **atts); (Function prototype from Expat, an outstanding C SAX parser by James Clark). RegistrationCallback

5 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 5 Event-Driven Parsers \\server01\active_files... startElement(... “ mirror ”...) startElement(... “ source ”...) charHandler( “ \\server01... ” ) endElement( “ source ” ) endElement( “ mirror ” )

6 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 6 Tree-Based Parsers \\server01\active_files... DOM_NodeList* list = domDoc->getChildNodes(); DOM_Node* node = list->item(0); string text = node->nodeValue();

7 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 7 Validation – DTDs Goal: Allow only one top-level element, called “link”, which must have exactly two child-elements called “host”, each of which has a “name” attribute. <!ATTLIST host name CDATA #REQUIRED > “Error at (file sample2.xml, line 4, column 28): Required attribute 'name' was not provided” (Apache’s Xalan, v. 1.3)

8 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 8 Validation – W3C Schema Language Goal: Allow only one top-level element, called “link”, which must have exactly two child-elements called “host”, each of which has a “name” attribute. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="UPE3" xmlns="UPE3" elementFormDefault="unqualified">

9 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 9 Why Use XML-Based Validation? To avoid writing program-based validation! Compare this (pseudo-)code: if (topElem != “mirror”) then reportError(...) end if while (topElem has children) child = get next child if (child != “source” AND child != “dest”) then reportError(...) end if do something end if To this DTD:

10 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 10 Agenda Introduction - "Why XML?" Section 1: XML Basics Section 2: Parsers and SAX and DOM (oh, my!) > Demonstration: "SysAdmin Dashboard" Section 3: XPath and XSLT Section 4: SOAP and WebServices Questions, Answers, and Evasions

11 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 11 Typical Log Output Task #8 started at 20040208.123921........ 20040208.123923|DELETED 10 rows from table 'employees' to db 'offsite_archival'. (2272 msec elapsed). 20040208.123925|UPDATED 22 rows from table 'checks' to db 'offsite_archival'. ( 2748 msec elapsed). 20040208.123927|XFERRED 8 rows from table 'holidays' to db 'offsite_archival'. (1871 msec elapsed). **** ERROR! **** 20040208.123928|DELETED failed on table 'holidays' at db 'offsite_archival'.Erro r reported: 10324("access denied"). (3449 msec elapsed). **** END OF ERROR **** 20040208.123931|XFERRED 50 rows from table 'sites' to db 'offsite_archival'. (2 704 msec elapsed)....

12 XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 12 Run "admin_dashboard.htm"... XML And Its UsesUPE Dearborn, 2/9/2004 Copyright 2004 by Blair Schneider McKayIntroductionCopyright 2004 by Blair Schneider McKay


Download ppt "XML And Its UsesUPE Dearborn, 2/9/2004 ParsersCopyright 2004 by Blair Schneider McKaySlide 1 Agenda Introduction - "Why XML?" Section 1: XML Basics Section."

Similar presentations


Ads by Google