View
294
Download
5
Category
Preview:
Citation preview
XML FundementalsXML Fundementals XML vs.. HTML XML vs.. HTML XML Document (elements vs. XML Document (elements vs.
attributes) attributes) XML and RDBMS XML and RDBMS XML Schema (DTD; XSD)XML Schema (DTD; XSD) XPATHXPATH XSLT (XSL; XSLT) XSLT (XSL; XSLT) SYSTEM.XMLSYSTEM.XML XSD Classes and TypesXSD Classes and Types Serialization ProcessSerialization Process
Any need for re-query or sorting of existing data required a new round-trip to the server.
HTMLHTML
<?xml version="1.0" encoding="utf-8" ?>
<CUSTOMERSORDERS>
<CUSTOMERS CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" ContactName="Alfreds Futterkiste" ContactTitle="Sales Representative" Phone="030-0074321">
<ORDERS OrderID="10643" OrderDate="2000-08-25T00:00:00"/>
<ORDERS OrderID="10692" OrderDate="2000-10-03T00:00:00"/>
<ORDERS OrderID="10702" OrderDate="2000-10-13T00:00:00"/>
<ORDERS OrderID="10835" OrderDate="2001-01-15T00:00:00"/>
<ORDERS OrderID="10926" OrderDate="2001-03-04T00:00:00"/>
<ORDERS OrderID="10952" OrderDate="2001-03-16T00:00:00"/>
<ORDERS OrderID="11011" OrderDate="2001-04-09T00:00:00"/>
</CUSTOMERS>
<CUSTOMERS CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" ContactName="Ana Trujillo" ContactTitle="Owner" Phone="(5) 555-4729">
<ORDERS OrderID="10759" OrderDate="2000-11-28T00:00:00"/>
</CUSTOMERS>
</ CUSTOMERSORDERS >
HTML and XML are both “firewall friendly”
XML separate data from presentation
XML is not a markup language
XML defines the data content and structure
HTML vs. XMLHTML vs. XML
Anatomy of XML Anatomy of XML DocumentDocument
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE books SYSTEM “books.dtd”><?xml-stylesheet type="text/xsl“ href="books.xsl" ?><books xmlns=“http://schema.mycomp.com/books” xmlns:uk=“xxxxxx” >
<book isbn="0-00-649845-0“ ><title> Op-Centre </title><author>Steve Pieczenik</author><price>25.99</price>
</book><book isbn="0-201-63361-2">
<title>Design Patterns</title><author>Erich Gamma</author><author>Richard Helm</author><author>Ralph Johnson</author><uk:price>34.00</uk:price>
</book></books>
PrologProlog Root Root ElementElement
NamespaceNamespace ElemeElementnt
AttributeAttribute DATA / PCDATADATA / PCDATA
Creating XML Creating XML DocumentsDocuments
Messages
Relationaldatabases
Server Pages
Legacy systems
Other XML documents
XMLdocument
XMLdocument
<books> <book isbn="0-00-649845-0"> <title>Op-Centre<title> <author>Steve Pieczenik</author> <price>25.99</price> </book> <book isbn="0-201-63361-2"> <title>Design Patterns</title> <author>Erich Gamma</author> <price>59.00</price> </book> <book isbn="0-201-63361-2"> <title>Design Patterns</title> <author>Ralph Johnson</author> <price>59.00</price> </book> <book isbn="0-201-63361-2"> <title>Design Patterns</title> <author>Ralph Johnson</author> <price>59.00</price> </book></books>
The hierarchical nature of The hierarchical nature of XML XML
<books> <book isbn="0-00-649845-0"> <title>Op-Centre<title> <author>Steve Pieczenik</author> <price>25.99</price> </book> <book isbn="0-201-63361-2"> <title>Design Patterns</title> <author>Erich Gamma</author> <author>Richard Helm</author> <author>Ralph Johnson</author> <price>59.00</price> </book></books>
How would you?1. Add new Author that has no book’s isbn yet.2. Remove the ‘0-00-649845-0’ row but keep the
author ‘Steve Pieczenik’.3. Change the title ‘Design Patterns’ without
having to do it in many places.
isbn title author price0-00-649845-0 Op-Centre Steve Pieczenik 5.990-201-63361-2 Design Patterns Erich Gamma 34.990-201-63361-2 Design Patterns Richard Helm 34.990-201-63361-2 Design Patterns Ralph Johnson 34.99
SELECT Books.isbn, Books.title, Authors.name as 'author', Books.price FROM Books, BooksAuthors, Authors WHERE Books.isbn = BooksAuthors.isbn and BooksAuthors.AuthorID = Authors.AuthorID
Hierarchical support in relational Hierarchical support in relational databases 1/2databases 1/2
isbn title price0-00-649845-0 Op-Centre 5.990-201-63361-2 Design Patterns 34.99
‘BooksAuthors’ table
isbn AuthorID0-00-649845-0 220-201-63361-2 250-201-63361-2 260-201-63361-2 27
AuthoorID Name22 Steve Pieczenik25 Erich Gamma26 Richard Helm27 Ralph Johnson
‘Authors’ table
‘Books’ table
Hierarchical support in relational Hierarchical support in relational databases 2/2databases 2/2
Select Books.*, Authors.name as Authors from Books, BooksAuthors, Authorswhere Books.isbn = BooksAuthors.isbn and BooksAuthors.AuthorID = Authors.AuthorIDorder by Books.isbn for xml auto
XML SchemaXML Schema DTDDTD (Old W3C standard, supported by all …) (Old W3C standard, supported by all …) XDRXDR (Microsoft only) (Microsoft only) XSDXSD (W3C standard as of May 2001) (W3C standard as of May 2001)
ELEMENTSELEMENTS
DTDDTD XDR / XSDXDR / XSD
Min OccursMin Occurs Max OccursMax Occurs
?? 00 11
11 11
** 00 **
++ 11 **
Bookstore DTD - Sample Bookstore DTD - Sample
<!ELEMENT books (book*)><!ELEMENT books (book*)><!ELEMENT book (title, author+, price)><!ELEMENT book (title, author+, price)><!ATTLIST book isbn CDATA <!ATTLIST book isbn CDATA
#REQUIRED>#REQUIRED><!ELEMENT title (#PCDATA)><!ELEMENT title (#PCDATA)><!ELEMENT author (#PCDATA)><!ELEMENT author (#PCDATA)><!ELEMENT price (#PCDATA)><!ELEMENT price (#PCDATA)>
DEMO – Validating XML with DTD DEMO – Validating XML with DTD
Bookstore XSD - SampleBookstore XSD - Sample
Open SampleOpen Sample
Using XSLT CapabilitiesUsing XSLT Capabilities
An XSLT style sheet can perform a An XSLT style sheet can perform a wide range of transformationswide range of transformations
Examples:Examples: Map one XML grammar to anotherMap one XML grammar to another Filter unwanted dataFilter unwanted data Sort XML dataSort XML data Restructure an XML documentRestructure an XML document Perform computationsPerform computations
Transforming XML into a Different XML Transforming XML into a Different XML GrammarGrammar
XML document
XSLT style sheet
+XSLT
processor
Different XML grammar
<employees> <employee> <name>Reid</name> <salary>91000</salary> </employee> …</employees>
<employees> <employee> <name>Reid</name> <salary>91000</salary> </employee> …</employees>
<staff> <staff-member name="Reid" pay="91000"/> …
</staff>
<staff> <staff-member name="Reid" pay="91000"/> …
</staff>
Transforming XML into Transforming XML into HTMLHTML
XML document
XSLT style sheet
+XSLT
processor
XHTML document (XML compliant)
<employees> <employee> <name>Reid</name> <salary>91000</salary> </employee> …</employees>
<employees> <employee> <name>Reid</name> <salary>91000</salary> </employee> …</employees>
<HTML><TABLE> <TR> <TD>Reid</TD> <TD>91000</TD> </TR> …</TABLE></HTML>
<HTML><TABLE> <TR> <TD>Reid</TD> <TD>91000</TD> </TR> …</TABLE></HTML>
What Is XPath?What Is XPath? XPath maps an XML document to a tree of nodesXPath maps an XML document to a tree of nodes Use XPath expressions to identify, select, and Use XPath expressions to identify, select, and
manipulate nodes in an XML hierarchymanipulate nodes in an XML hierarchy Use location paths to select nodesUse location paths to select nodes XPath operators XPath operators andand functions functions
Why Use XPath? Why Use XPath? In XSLT style sheets,for pattern matching
In SQL Server 2000,to address result-set nodes
In XPointer, to link documents together
System.xml to selectnodes programmatically
XMLXML
XMLXML
XMLXML
XPathXPath
Using XSLT on the Using XSLT on the ServerServer
Apply a stylesheet to a document on the serverApply a stylesheet to a document on the server Transform between different schemasTransform between different schemas
Merge data sourcesMerge data sources Conversion based on business processes and requirementsConversion based on business processes and requirements
Convert XML into well-formed HTMLConvert XML into well-formed HTML
XSLT
XSLT
XSLT
DifferentXML grammar
XML
Anotherserver
IE5client
Otherbrowser
HTML
XML
SYSTEM.XMLSYSTEM.XML Hello System.XmlHello System.Xml
Quick overview - libraries tools and goals.Quick overview - libraries tools and goals. Integrating XML into your applications.Integrating XML into your applications.
XML & Performance = streaming-based modelXML & Performance = streaming-based model XML Transformation with performance in mind.XML Transformation with performance in mind. DemoDemo Optional: Accessing Raw SOAP Messages in Optional: Accessing Raw SOAP Messages in
ASP.NET Web ServicesASP.NET Web Services Hierarchical vs. Relational representation of Hierarchical vs. Relational representation of
data.data. Why do we need them both.Why do we need them both. XML Integration with Relational Data.XML Integration with Relational Data. DemoDemo
Hello System.XmlHello System.Xml System.XmlSystem.Xml System.Xml.SchemaSystem.Xml.Schema System.Xml.SerializationSystem.Xml.Serialization System.Xml.XPathSystem.Xml.XPath System.Xml.Xsl System.Xml.Xsl
Design GoalsDesign GoalsCompliance with the W3C standardsCompliance with the W3C standardsExtensibilityExtensibilityPluggable architecturePluggable architecturePerformancePerformanceTight integration with ADO.NETTight integration with ADO.NET
ToolsToolsxsd.exexsd.exeXml schema designerXml schema designerData Adapter WizardData Adapter WizardExternal toolsExternal tools
XML & Performance = XML & Performance = streaming-based modelstreaming-based model
XmlReaderXmlReader Minimal caching for forward-only pull model Minimal caching for forward-only pull model
parsing.parsing. XmlValidatingReaderXmlValidatingReader
Forward-only validation.Forward-only validation. XPathNavigator XPathNavigator
cursor style navigationcursor style navigation minimizes node creation to a single virtual nodeminimizes node creation to a single virtual node yet provides random access to the document.yet provides random access to the document. does not require a complete node tree to be built in does not require a complete node tree to be built in
memory (DOM) memory (DOM) XslTransformXslTransform
Incremental streaming outputIncremental streaming output. .
XML Transformation XML Transformation with performance in mindwith performance in mind
XML Transformation XML Transformation with performance in mindwith performance in mind
Hierarchical vs. Relational representation of Hierarchical vs. Relational representation of datadata
Hierarchical vs. Relational representation of Hierarchical vs. Relational representation of datadata
Hierarchical vs. Relational Hierarchical vs. Relational representation of datarepresentation of data
Discussion: Why do we Discussion: Why do we need them both?need them both?
XML Integration with Relational Data XML Integration with Relational Data and ADO.NETand ADO.NET
XML Integration with Relational Data XML Integration with Relational Data and ADO.NETand ADO.NET
When to load XML directly into a When to load XML directly into a
DataSetDataSet When to synchronize an When to synchronize an XmlDataDocument with a DataSet XmlDataDocument with a DataSet
Queries of data in the DataSet are Queries of data in the DataSet are easier using SQL than XPath easier using SQL than XPath
XPath queries are needed over XPath queries are needed over data in the DataSet. data in the DataSet.
Preservation of element ordering Preservation of element ordering in the source XML is not critical. in the source XML is not critical.
Preservation of element ordering Preservation of element ordering in the source XML is critical. in the source XML is critical.
White space between elements and White space between elements and formatting does not need to be formatting does not need to be preserved in the source XML. preserved in the source XML.
White space and formatting White space and formatting preservation in the source XML is preservation in the source XML is critical. critical.
Synchronizing a DataSet Synchronizing a DataSet with an XmlDataDocumentwith an XmlDataDocument
Sample Sample CodeCode… …
Serialization ProcessSerialization Process
Classes used by the default Classes used by the default Serialization Process Serialization Process
Classes used with Serialized Streams, Classes used with Serialized Streams, File Stream, Memory Stream, Net File Stream, Memory Stream, Net Stream Stream
Binary Formatter Binary Formatter SOAP Formatter SOAP Formatter De-serialization De-serialization
XSD Classes and TypesXSD Classes and Types
Using xsd.exe to generate schema Using xsd.exe to generate schema from classes from classes
Using xsd.exe to generate classes Using xsd.exe to generate classes from schema from schema
XSD TypesXSD Types DemoDemo
ReviewReview XML vs.. HTML XML vs.. HTML XML Document (elements vs. XML Document (elements vs.
attributes) attributes) XML and RDBMS XML and RDBMS XML Schema (DTD; XSD)XML Schema (DTD; XSD) XPATHXPATH XSLT (XSL; XSLT) XSLT (XSL; XSLT) SYSTEM.XMLSYSTEM.XML XSD Classes and TypesXSD Classes and Types Serialization ProcessSerialization Process
Recommended