1 / 24

.NET and XML (or XML in .NET)

.NET and XML (or XML in .NET). David Oguns Matt Harding. Agenda. Microsoft Design Goals Major XML Namespaces XML Reading and Writing DOM in .NET What the future holds. Design Goals. W3C Standards Compliant Extensible Pluggable Performance Integration with ADO.NET. XML Namespaces .

eileen
Download Presentation

.NET and XML (or XML in .NET)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .NET and XML(or XML in .NET) David Oguns Matt Harding

  2. Agenda • Microsoft Design Goals • Major XML Namespaces • XML Reading and Writing • DOM in .NET • What the future holds

  3. Design Goals • W3C Standards Compliant • Extensible • Pluggable • Performance • Integration with ADO.NET

  4. XML Namespaces • System.Xml • System.Xml.Schema • System.Xml.Serialization • System.Xml.XPath • System.Xml.Xsl

  5. XML Reading • Exposed through a few classes: • XmlReader abstract class • XmlTextReader, XmlValidatingReader, XmlNodeReader implementations • Uses pull parsing • Allows for recursive decent approach • *Apple Property List Example

  6. XML Writing • XmlWriter abstract class • One implementation => XmlTextWriter • Methods are almost parallel to XmlReader class • *Apple Property Lists Revisited

  7. DOM in .NET • More or less the same as in Java • XmlDocument inherits from XmlNode which implements IXPathNavigable.

  8. New for 2005!! • New goals • Improve performance • Enhance usability • Querying data Sources • Typing • Schema (enhanced support)

  9. New for 2005!! • Top 10 new changes decided by Mark Fussell, his dog, and his bearded dragon • 10) Static Creation Methods on XmlReader and XmlWriter9) XML Standards Support by Default8) Universal Type Support and Conversion7) XmlReader and XmlWriter Usability6) The XQuery Language5) Security4) Easier XPath Queries with Namespaces3) The XPathDocument as a Better DOM2) XPathEditableNavigator, an Updatable Cursor1) Performance

  10. 10) Static creations • Create XMLReader and XMLWriter statically • Why? • To create an easer and more flexible ways of configuring • Create and hide optimizations • Created a way to create pipes between different writers and readers • Code • XmlReader r = XmlReader.Create("books.xml"); • XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add("books.xsd"); settings.XsdValidate = true; settings.IgnoreWhitespace = true; XmlReader reader = XmlReader.Create("books.xml",settings); while(reader.Read()) {}

  11. 9) XML Standards Support • Framework Version 1 was not conformant • Framework Version 2 added support for DTD’s • This means it is now a conformant XML parser • Other changes • XMLWriter checks for invalid names • XMLWriter checks for invalid characters • Can check specific sub tree for specific schema or DTD

  12. 9) XML Standards Support • Code • XmlDocument doc = new XmlDocument(); doc.Load("books.xml");XmlNode node = doc.SelectSingleNode("//book"); XmlNodeReader nodereader = new XmlNodeReader(node); XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add("http://example.books.com", "books.xsd"); settings.XsdValidate = true; XmlReader reader = XmlReader.Create(nodereader, settings); while(reader.Read()) {}

  13. 8 & 7 ) Usability • New Functions • ReadSubTree() • Using statements for both XMLReader & XMLWriter • ReadAsObject( System.type type) & WriteAsObject(object value) • Type Support • XQuery requires this • Does this with or without Schema

  14. 8 & 7 ) Usability • Code (object) • public class Book { public string title; public double price; } • Code ( reading ) • if (reader.ReadToDescendant("book")) { do { Book book = (Book)(reader.ReadAsObject(typeof(Book))); ProcessBook (book) // Do some processing on the book } while (reader.ReadToNextSibling("book")); }

  15. 6 ) XQuery • Justification • Inteligently express quiries across all kinds of data • A language with quires are concise and easily understood • The XQuery language is to XML as the SQL language is to relational databases.

  16. 6 ) XQuery • Primarily the XQuery language was designed to provide the following benefits: • A greater expressiveness with an ability to perform complex query operations such as joins, ordering, and sorting. • A human-friendly, non-XML syntax. • Strong typing at both runtime and compile time. That is, through the use of W3C XML Schemas types, you can query for particular types of data in the data source, such as "find all the books within this document." • A rich set of functions and operators to operate on the XML Schema types. Whereas XML Schema only defined the types, XQuery has defined the operations that are allowed on those types. (taken from MSDN)

  17. 5 ) Security • Two important changes • XML now has the same privalages as normal code • .NET Code Access Security • Ability to prohibit DTD parsing when loading an XML document

  18. 4 ) Namespaces and XPATH • This was the thorn in most people sides • Still very complicated but is more possible that before • You can define a namespace object • Then assign it to an xpath object • Run the query and it will return an iterator of all objects in that namespace

  19. 3 ) XPathDocument vs DOM • Microsoft didn’t like DOM • Felt it was to limited in parsing, API, and its data model • Created XPathDocument • Can use an XMLWriter for output • Fully Typed • Random access curser-style API • Node level Entry • Can accept or reject changes across whole document • XML files can be read from file, streams, and URL’s

  20. 2 ) XpathEditableNavigator • Allows you to do what you please when creating and editing a document • You can • Append Child • Prepend Child • Insert Before • Insert After • Delete Current • … • Note sure what the behavior is but you can see that you can do anything in an XML document from anywhere

  21. 1 ) Performance • The big performance improvements are: • The XmlTextReader and the XmlTextWriter are on average twice as fast as the V1.1 release. This improvement has been achieved through a significant redesign and rewrites that optimized for the most common code path. • The XmlReaders created via the static Create methods have the same performance as the constructed types. since these share the same code path. • The XmlWriters created via the static Create methods have better performance than XmlTextWriter. • XML Schema validation is approximately 20 percent faster and is more compliant to the W3C standard. • The XSLT performance is three to four times faster.( from MSDN )

  22. 1 ) Performance

  23. References • We didn’t cover everything: • http://msdn.microsoft.com • .NET and XML, Neil M. Bornstein, O’Reily • Microsoft Visual C# .NET, Mickey Willams, Microsoft Press • Microsoft also uses an XML based documenting tool for .NET languages

  24. Closing • If you are writing applications that use XML and/or web services extensively, consider using the .NET platform to take advantage of Microsoft’s elegant solutions. • Microsoft is working on new and amazing things if you have a problem wait a bit and Microsoft might fix it. • 2005 will be an amazing jump in XML tools and development

More Related