Download presentation
Presentation is loading. Please wait.
Published byOwen Sutton Modified over 9 years ago
1
Chapter 13 XML Yingcai Xiao
2
What is XML? What is it for? Examples How to write? How to validate? How to read? How to display? How to format? How to translate?
3
Extensible Markup Language. De facto data language. http://www.w3.org/TR/REC-XML. HTML expresses appearance; XML describes data and its structure. Text based (platform-independent). Object-oriented data representation. Has no predefined tags. Provides rules to format data. Many XML parsers already available. Strong XML support in the FCL.. XML
4
XML Example (Guitars.xml) Gibson SG 1977 Tobacco Sunburst Rosewood Fender Stratocaster Black Maple
5
XML Example (Guitars.xml) Document element (root): Guitars. Guitar elements are children of Guitars. Make contain data. Empty element: Nested elements. The content of an XML document can be viewed as a tree. Attributes
6
XML Description XML Elements: text-based object-oriented data (object) Error checking? Text-based object-oriented type (class) definition? Early days: document type definitions (DTDs). Today: XML Schema Definitions (XSDs). http://www.w3.org/TR/xmlschema-1 http://www.w3.org/TR/xmlschema-2. Schema: a collection of meta data. Meta data: data that describes data. XSD is an XML-based language for describing XML documents and the types that they contain.
7
Example: Guitars.xsd
8
Examples\c13\Validate\ Typo => xsd:Year should be xsd:string run.bat Validate Guitars.xml Guitars.xsd run-bad-xml.bat Validate Guitars-Missing-Make.xml Guitars.xsd Example: Guitars.xsd
9
XML Parsers Most XML parsers implement one of two popular APIs: DOM or SAX. DOM: Document Object Model http://www.w3.org/TR/DOM- Level-2-Core. SAX: Simple API for XML, unofficial, http://www.saxproject.org. FCL XmlDocument, managed DOM implementation Examples of using XmlDocument: Validate ReadXml XmlView Transform Quotes ExpressAnalyzer
10
ReadXml.cs (also see XmlView) using System; using System.Xml; class MyApp { static void Main () { XmlDocument doc = new XmlDocument (); doc.Load ("Guitars.xml"); XmlNodeList nodes = doc.GetElementsByTagName ("Guitar"); foreach (XmlNode node in nodes) { Console.WriteLine(“Maker {0}; Model {1}", node["Make"].InnerText, node["Model"].InnerText); }
11
XML Path Language For addressing parts of an XML document. “/Guitars/Guitar” is an XPath expression. http://www.w3.org/TR/xpath. http://www.w3.org/TR/xpath XPath
12
XSL is a language for expressing style sheets. Adopted from CSS, a file that describes how to display an XML document of a given type.CSS Styling requires a source XML documents, containing the information that the style sheet will display and the style sheet itself which describes how to display a document of a given type. It supports: Formatting Objects. It also adds a transformation language for XML documents: XSLT. Examples\c13\Quotes\Quotes.xsl http://winserv1.cs.uakron.edu/Examples/C13/Quotes/quotes.aspx XSL
13
Extensible Stylesheet Language Transformations. Converting XML documents into HTML documents. Converting HTML documents into other XML documents. Examples\c13\Transform\Transform.cs http://winserv1.cs.uakron.edu/Examples/C13/Transform/Quotes.html XSL Transformations (XSLT)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.