Benjamin Gan (Bengan@iss - Nus.edu - SG) Institute of Systems Science National University of Singapore
Benjamin Gan (Bengan@iss - Nus.edu - SG) Institute of Systems Science National University of Singapore
NET
XML
© 2004 ISS. The contents contained in this document may not be reproduced in any form or by any means, without the written permission of ISS, other than for the purpose for which it has been supplied.
WebService
Database
Configuration
Documents
Repository SmartPhones
Data PDA
ATA/SE-WSNET/CPM/XML.PPT/V2.0 Web Services using .NET Slide 7
© 2004 ISS. All rights reserved
Weaknesses of XML
Text based
Inefficient
storage format compared to binary
Performance overhead for transmission
No fixed tag semantics
Tag interpretations are domain specific and semantics may clash
¾ Standards are needed for domain specific semantics (eg bioinformatics)
XML original intent is for document exchange
Specification for distributed computing is not complete
¾ No standard for transactions, objects, security, etc
¾ WSA, GXA, ebXML, etc are working on WS-Transaction, WS-Security, etc
Comment markups
¾ Comments may appear anywhere in a document outside other markup
<!-- Here are the comments -->
ATA/SE-WSNET/CPM/XML.PPT/V2.0 Web Services using .NET Slide 10
© 2004 ISS. All rights reserved
XML Document Markups
Processing instructions markups
¾ This is an escape hatch to provide information to an application
<?xml version="1.0" encoding="utf-8"?>
CDATA sections markup
¾ This markup instructs the parser to ignore markup characters (< or &)
<![CDATA[ b = ( i < 3); ]]>
Document type declarations (DTD) markups
¾ DTD places constraints on the XML structure
¾ DTD support the use of predefined storage units (predefined types)
¾ DTD contains markup declarations that provide a grammar for the document
<!DOCTYPE greeting [<!ELEMENT greeting (#PCDATA)>]>
<greeting>Hello, world!</greeting>
¾ Markup declarations can be placed on element types, attribute list, entities
and notations
ATA/SE-WSNET/CPM/XML.PPT/V2.0 Web Services using .NET Slide 11
© 2004 ISS. All rights reserved
XML Elements
Element Markups (tags)
Each element has a begin and end tag names
¾ Tag names are case sensitive [a..z, A..Z, _]{a..z, A..Z, 0..9, _, -, ., :}*
¾ Tag names beginning with “xml” are reserved
<TagName>Hello World</TagName>
Elements can be empty <Bonus></Bonus> <Bonus/>
Elements are serialized in the order they are defined
Element children are serialized between tags
<Employee>
<Name>Benjamin Gan</Name>
<HiredDate>15 May 1997</HiredDate>
<Position>Associate</Position> Element
<Salary>$1,000.00</Salary> Children
<Bonus/>
</Employee>
ATA/SE-WSNET/CPM/XML.PPT/V2.0 Web Services using .NET Slide 12
© 2004 ISS. All rights reserved
XML Attributes
XML attributes describe the XML element
XML attributes are define inside the XML element start tag
XML attributes are define as name and value pairs
¾ The names must be unique within the element
¾ The values must be text only enclosed in “” or ‘’
¾ Attributes are not ordered (serialized order are implementation dependent)
<height units=“inches”>68</height>
<height units=‘cm’>140</height>
<ISS:Employee xmlns:ISS=“urn:www.iss.nus.edu.sg-gan-wsnet”>
<Name>Benjamin Gan</Name>
<ISS:Position>Teacher</ISS:Position>
ISS
</ISS:Employee>
in.xml
out.xml
in.xsl
XML transformer
Built-in Datatypes
Derived Datatypes
Differences
SAX sequentially access the XML document
¾ SAX require less memory (smaller input, work and output buffers)
¾ SAX facilitates searching large documents for small pieces of information
¾ SAX can abort processing large documents when task is completed
DOM randomly access the XML document in memory
¾ DOM constructs the data structure in memory
¾ DOM is useful in processing complex queries with contexts
Serialization
Schema • Contains classes that are
• Provides standards- used to serialize objects
based support for XML into XML format
Schemas (XSD) documents or streams
<?xml version='1.0'?>
<Employee xmlns="urn:gan-employee-schema">
<Name>Benjamin Gan</Name>
<HiredDate>15 May 1997</HiredDate>
<Position>Associate</Position>
<Salary>$1,000.00</Salary>
<Bonus/> InvalidEmployee.xml
</Employee>
XmlDataDocument DataSet
Sync
DataTable
SqlConnection SqlDataAdapter
XmlTextReader XmlNodeReader
XmlReader SqlCommand SqlDataReader
SQL Server .NET Data Provider
Xml
Xml
Document
Document SQL Server
7.0+
XmlSerializationWriter
Code Generated to Temp Assembly
XmlWriter
Serialize
<Employee> public class EmployeeType {
<Name>Benjamin Gan</Name> public string Name;
… XmlSerializer …
</Employee> Complex } Class
Type Deserialize
XmlReader
XmlSerializationReader
Code Generated to Temp Assembly
[XmlElement(DataType="date")]
public DateTime HiredDate;
XML
XML
doc
doc