310 likes | 551 Views
XML Fundementals. XML vs.. HTML XML Document (elements vs. attributes) XML and RDBMS XML Schema (DTD; XSD) XPATH XSLT (XSL; XSLT) SYSTEM.XML XSD Classes and Types Serialization Process. HTML. Any need for re-query or sorting of existing data required a new round-trip to the server.
E N D
XML Fundementals • XML vs.. HTML • XML Document (elements vs. attributes) • XML and RDBMS • XML Schema (DTD; XSD) • XPATH • XSLT (XSL; XSLT) • SYSTEM.XML • XSD Classes and Types • Serialization Process
HTML Any need for re-query or sorting of existing data required a new round-trip to the server.
HTML vs. XML 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 <?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 >
Anatomy of XML Document • <?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” > • <bookisbn="0-00-649845-0“ > • <title> Op-Centre</title> • <author>Steve Pieczenik</author> • <price>25.99</price> • </book> • <bookisbn="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>
Creating XML Documents Legacysystems XML document Relational databases ServerPages OtherXMLdocuments Messages
The hierarchical nature of 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> <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> <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>
Hierarchical support in relational databases 1/2 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 • How would you? • Add new Author that has no book’s isbn yet. • Remove the ‘0-00-649845-0’ row but keep the author ‘Steve Pieczenik’. • Change the title ‘Design Patterns’ without having to do it in many places. ‘Books’ table ‘Authors’ table ‘BooksAuthors’ table
Hierarchical support in relational databases 2/2 Select Books.*, Authors.name as Authors from Books, BooksAuthors, Authors where Books.isbn = BooksAuthors.isbn and BooksAuthors.AuthorID = Authors.AuthorID order by Books.isbn for xml auto
XML Schema • DTD (Old W3C standard, supported by all …) • XDR (Microsoft only) • XSD (W3C standard as of May 2001)
Bookstore DTD - Sample <!ELEMENT books (book*)> <!ELEMENT book (title, author+, price)> <!ATTLIST book isbn CDATA #REQUIRED> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT price (#PCDATA)> DEMO – Validating XML with DTD
Bookstore XSD - Sample • Open Sample
Using XSLT Capabilities • An XSLT style sheet can perform a wide range of transformations • Examples: • Map one XML grammar to another • Filter unwanted data • Sort XML data • Restructure an XML document • Perform computations
Transforming XML into a Different XML Grammar XML document Different XML grammar + XSLT processor XSLT style sheet <employees> <employee> <name>Reid</name> <salary>91000</salary> </employee> … </employees> <staff> <staff-member name="Reid" pay="91000"/> … </staff>
Transforming XML into HTML XML document XHTML document (XML compliant) + XSLT processor XSLT style sheet <employees> <employee> <name>Reid</name> <salary>91000</salary> </employee> … </employees> <HTML><TABLE> <TR> <TD>Reid</TD> <TD>91000</TD> </TR> … </TABLE></HTML>
What Is XPath? • XPath maps an XML document to a tree of nodes • Use XPath expressions to identify, select, and manipulate nodes in an XML hierarchy • Use location paths to select nodes • XPath operators and functions
XPath XML XML XML Why Use XPath? In XSLT style sheets,for pattern matching System.xml to selectnodes programmatically XPath In XPointer, to link documents together In SQL Server 2000,to address result-set nodes
Using XSLT on the Server • Apply a stylesheet to a document on the server • Transform between different schemas • Merge data sources • Conversion based on business processes and requirements • Convert XML into well-formed HTML Another server XSLT Different XML grammar Other browser XML XSLT HTML IE5 client XSLT XML
SYSTEM.XML • Hello System.Xml • Quick overview - libraries tools and goals. • Integrating XML into your applications. • XML & Performance = streaming-based model • XML Transformation with performance in mind. • Demo • Optional: Accessing Raw SOAP Messages in ASP.NET Web Services • Hierarchical vs. Relational representation of data. • Why do we need them both. • XML Integration with Relational Data. • Demo
Hello System.Xml • System.Xml • System.Xml.Schema • System.Xml.Serialization • System.Xml.XPath • System.Xml.Xsl Tools xsd.exe Xml schema designer Data Adapter Wizard External tools Design Goals Compliance with the W3C standards Extensibility Pluggable architecture Performance Tight integration with ADO.NET
XML & Performance = streaming-based model • XmlReader • Minimal caching for forward-only pull model parsing. • XmlValidatingReader • Forward-only validation. • XPathNavigator • cursor style navigation • minimizes node creation to a single virtual node • yet provides random access to the document. • does not require a complete node tree to be built in memory (DOM) • XslTransform • Incremental streaming output.
Hierarchical vs. Relational representation of data • Discussion: Why do we need them both?
Synchronizing a DataSet with an XmlDataDocument Sample Code …
Serialization Process • Classes used by the default Serialization Process • Classes used with Serialized Streams, File Stream, Memory Stream, Net Stream • Binary Formatter • SOAP Formatter • De-serialization
XSD Classes and Types • Using xsd.exe to generate schema from classes • Using xsd.exe to generate classes from schema • XSD Types • Demo
Review • XML vs.. HTML • XML Document (elements vs. attributes) • XML and RDBMS • XML Schema (DTD; XSD) • XPATH • XSLT (XSL; XSLT) • SYSTEM.XML • XSD Classes and Types • Serialization Process