Beruflich Dokumente
Kultur Dokumente
Objectives
Introduce
XML Including:
XML Schema
Explore
Contents
Have
The
XML Architecture
XML Schemata
.NET
Looking Back
Tightly
Proprietary,
Data
Non-extensible
solutions
XML!
XML
technologies introduced:
XML Schemata
.NET
& XML:
is XML?
Tags and Tag Sets
Components
Document
XML
The
of an XML Document
Instance
Document by Example
XML Parser
Language
Syntax rules
Widely
http://www.w3.org/TR/2000/REC-xml-20001006
Metadata:
Looks
XML Tag-Sets
Begin
Exceptions
are:
Promote
User definable
XML
Processing Instruction
Document
Type Declaration
Document
Instance
version information
An Internal declaration
<!DOCTYPE CustomerOrder [
<!-- internal DTD goes here! -->
]>
An External reference
<!DOCTYPE CustomerOrder
SYSTEM "http://www.myco.com/CustOrder.dtd">
Document
Instance
Root Element
Elements
Attributes
XMLData + DTD
<!-- XML Data-->
<a>
<b> Some </b>
<c> 100 </c>
<c> 101 </c>
</a>
DTD
Not Valid!
Valid
Whats a DTD?
DTD By Diagram
CustomerOrder
Customer
Person
Orders
OrderNo
Address
ProductNo
Address
ProductNo
Address
FName
ProductNo
OrderNo
LName
ProductNo
ProductNo
Orders
Orders
DTD By Example
http://www.myco.com/dtd/order.dtd
<?xml version = 1.0 encoding = UTF-8 ?>
<!DOCTYPE CustomerOrder [
<!ELEMENT CustomerOrder (Customer, Orders*) >
XML
Source
Document
XML
Parser
XML
Schema
Or
DTD
Validated
XML
Document
Knows
Is it Valid?
Creates
Programming
An
Defines
Tree-view of a document
W3C
http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
<?xml version=1.0?>
Parser
Dom Tree
XML
Document
Root Element
Child Element
Text
Child Element
Text
All
Microsoft
XML Parser
http://msdn.microsoft.com/xml/general/xmlparser.asp
IBM/Apache
Xerces
http://xml.apache.org
http://alphaworks.ibm.com
XML Schema
Whats
a Schema?
Schema
vs. DTDs
Datatypes
& Structure
Not Valid!
Valid
Whats a Schema?
Websters
The
Composed
of two parts:
Structure: http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/
Datatypes: http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/
Schemata
Unlike
More
datatypes
Complex types
Facets
Declaring
data types
<schema> by example
Built-in
Primitive Datatypes
Derived Datatypes:
User-defined
Based
Cannot
Can
May
May
May
May
Substitution
Abstract
complexContent
Groups
http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/
Specify
optional properties
Examples
of Constraining Facets:
Declaring Attributes
Declared
Value
pairs
Can
May
Based
Promotes
logical organization
Encourages
Facilitates
Improves
Must
maintenance
Schema readability
Referenced
Schema Namespaces
Equivalent
http://www.w3.org/TR/1999/REC-xml-names-19990114/
Used
to XML namespaces
Namespace
<schema
xmlns
xmlns:CO
>
= http://www.w3.org/2001/XMLSchema
= http://www.MyCompany.com/Schema
targetNamespace:namespace_prefix = some_URI...
Example:
targetNamespace:CO ="http://www.myCo.com/CO"
targetNamespace = http://www.myCo.com/CO
xmlns:CO=http://www.myCo.com/CO
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified
attributeFormDefault="qualified
elementFormDefault="qualified">
found at:
http://www.w3.org/TR/1999/REC-xpath-19991116
Language
Permits
Uses
Roadmap To Selection
Location
axis::node_test[ predicate ]
Location
Paths
Syntax
Syntax exists
.. instead of parent::node()
. instead self::node()
// instead of /descendant-or-self::node()/
Operators
To
CustomerOrder/Customer/Address[@AddrType]
To
CustomerOrder/Orders/ProductNo[1][$ProductNo]
Can
< (for <), > (for >), <= (for <=), etc
Can
and
or
is XSLT?
Basic Structure
Some
Template Rules
More
Advanced Structure
More
Transforming
It All
What is XSLT?
A sub-specification of XSL
http://www.w3.org/TR/1999/REC-xslt-19991116
Designed to be used independently of XSL
Designed primarily for the transformation needed in XSL
XSLT
Style
Sheet
XML
Source
Document
Source
Schema
Target
Schema
XML
Target
Document
Processor
then:
Process of Transmutation
<Orders >
<OrderNo> 10 </OrderNo>
<ProductNo> 100 </ProductNo>
<ProductNo> 200 </ProductNo>
</Orders >
<Orders >
<OrderNo> 20 </OrderNo>
<ProductNo> 501 </ProductNo>
</Orders >
XSLT
Stylesheet
XSLT Processor
<HTML>
<BODY>
<TABLE border = 3>
<TR>
<TD> 10 </TD>
<TD> 100</TD>
</TR>
<TR>
<TD> 10 </TD>
<TD> 200</TD>
</TR>
<TR>
<TR></TR>
<TD> 20 </TD>
<TD> 501 </TD>
</TR>
</TABLE>
</BODY>
</HTML>
Alchemy Anyone?
Need
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Use
Then
<xsl:template/>
<xsl:apply-templates />
</xsl:template>
<xsl:stylesheet>
Select a node and insert its value into the output stream
Many,
Conditional processing
Sorting
Repetition
<xsl:sort >
Etc
XML
Namespaces in .NET
Some
XML 1.0
XML Namespaces
http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/
http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/
XPath expressions
http://www.w3.org/TR/1999/REC-xpath-19991116
XSL/T transformations
http://www.w3.org/TR/1999/REC-xml-names-19990114/
XML Schemas
http://www.w3.org/TR/1998/REC-xml-19980210
http://www.w3.org/TR/1999/REC-xslt-19991116
http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
SOAP 1.1
http://msdn.microsoft.com/xml/general/soapspec.asp
.Serialization
System.Xml Namespace
Overall
Classes
Reading,
Classes
XmlReader
Abstract
Fast,
Base
Properties
of Interest
XmlWriter
Abstract
Fast,
Base
Properties
of Interest
Implement
Designed
Inherit
XmlDocument
Derived
Represents
Supports
Reading
Properties of Interest:
Methods of Interest
EntityHandling
Formatting
NameTable
ReadState
TreePosition
Validation
WriteState
XmlAttribute
XmlAttributeCollection
XmlCDataSection
XmlCharacterData
.XPath
XmlCharType
XmlComment
XmlConvert
XmlDataDocument
XmlDeclaration
XmlDocument
XmlDocumentFragment
XmlDocumentType
XmlElement
XmlEntity
XmlEntityReference
XmlNamedNodeMap
.Serialization
.Schema
XmlNode
XmlNodeReader
XmlNodeType
XmlNotation
XmlReader
XmlSpace
XmlText
XmlTextReader
XmlTextWriter
XmlUrlResolver
XmlWhitespace
XmlWriter
...
XmlDocument By Example
using System.Xml;
//Create an XmlDocument, Load it, Write it to the Console
//One way:
XmlDocument xDoc = new XmlDocument();
xDoc.Load( C:\\myData.xml");
xDoc.Save( Console.Out);
//Second way (Use a XmlTextReader to read in load the XML):
XmlTextReader reader = new XmlTextReader(C:\\myData.xml");
xDoc.Load( reader );
xDoc.Save( Console.Out);
//Third way (Use a XmlTextWriter to output the XML document):
XmlTextWriter writer = new XmlTextWriter( Console.Out );
writer.Formatting = Formatting.Indented;
xDoc.WriteContentTo( writer );
writer.Flush();
Console.WriteLine();
writer.Close();
System.Xml.Xsl Namespace
Provides
Some
of the classes:
XsltTransform
Four
Load a stylesheet
Transform!
Transformation By Example
Using System.Xml.Xsl;
// 1. Create a XslTransform object
XslTransform xslt = new XslTransform();
// 2. Load an XSL stylesheet
xslt.Load("http://somewhere/favorite.xsl");
// 3 & 4. Load the XML data file & transform!
xslt.Transform(http://somewhere/mydata.xml,
C:\\somewhere_else\\TransformedXmlOutput.xml
);
Summary
XML
XML
XML,
.NET
Section 4: Q&A
Using
Some
XmlDocument
XmlDataDocument
XmlNavigator
XmlDataNavigator
etc
.NET
http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
W3C specification
http://www.w3.org/TR/REC-xml-names/
Create
Used
For example:
xmlns=urn:schemas-microsoft-com:customerdata
May
xmlns:ms=urn:schemas-microsoft-com:data
Use
Documents