XML
Extensible Markup Language: An Introduction
The Enabling Technology for
B2B eCommerce and Web Site Development
Minder Chen, Ph.D.
[email protected]
References
•
XML Programming by R. Allen Wyke, Sultan Rehman, Brad Leup, Microsoft Press, 2002
•
Al McKinnon, Linda McKinnon, XML, Course Technology, July 22, 2002
• Online resources:
– XML Poster: http://www.zapthink.com/download/download.html#
–
Our XML resources:
» Microsoft XML resources:
–
–
» http://msdn.microsoft.com/xml/
Dedicated XMLsites:
» http://www.xml.com/
and http://www.xmlsoftware.com/
XML-Data standard
» http://www.w3.org/TR/1998/NOTE-XML-data/
–
XML namespaces: http://www.w3.org/TR/REC-xml-names/
–
XSL standard:
http://www.w3.org/TR/1998/WD-xsl-19981216.pdf
The World Wide Web Consortium XML Workgroup: http://www.w3.org/XML/Activity
Timothy Bray's (co-editor of the XML spec.) XML page
» http://www.textuality.com/xml/
–
–
–
http://www.builder.com/Authoring/XmlSpot/
–
http://www.oasis-open.org/cover/xml.html#applications
© Minder Chen, 1998-2008
XML - 2
HTML and XML
Courselist.doc
Courselist.htm
Courselist.xml
Plain English
HTML
XML
<html><head><title>Co
urse List</title></head>
<body>
<ol>
<li>Course List
<ul>
<li> AITC offers
<li> Intr. to XML
<li> basic-level
<li> May 29, 1999
<li> Price $220
<li> Reston Lab
</ul>
</ol>
</body></html>
<?xml version="1.0" ?>
<courselist>
<course level="basic">
<firm>AITC</firm>
<title>Intr. to XML</title>
<date>May 29, 1999
</date>
<price currency="USD">
220
</price>
<location>Reston Lab
</location>
</course>
</courselist>
Course List:
AITC offers
Intr. to XML
a basic-level course
on May 29, 1999
Price $220
at Reston Lab
© Minder Chen, 1998-2008
XML - 3
Document
• Structure
• Content
• Display
© Minder Chen, 1998-2008
Simple E-mail document
Receiver: John
Sender: Harry
Subject: Hello
============================
Dear John,
Hello!
………………...
This is the document for you!
Harry
May 12, 1999
XML - 4
What is XML?
Extensible Markup Language, abbreviated XML, describes a class of data objects called XML documents
and partially describes the behavior of computer programs which process them. XML is an application
profile or restricted form of SGML, the Standard Generalized Markup Language [ISO8879]. By
construction, XML documents are conforming SGML documents.
XML documents are made up of storage units called entities, which contain either parsed or unparsed data.
Parsed data is made up of characters, some of which form character data, and some of which form markup.
Markup encodes a description of the document's storage layout and logical structure. XML provides a
mechanism to impose constraints on the storage layout and logical structure.
A software module called an XML processor is used to read XML documents and provide access to their
content and structure. It is assumed that an XML processor is doing its work on behalf of another module,
called the application. This specification describes the required behavior of an XML processor in terms of
how it must read XML data and the information it must provide to the application.
XML stands for "Extensible Markup Language".
• It is extensible because it is not a fixed format like HTML.
• It is designed to enable the use of simplified SGML on the
World Wide Web.
• A language and set of rules for formally defining markup
languages
• A markup meta-language
© Minder Chen, 1998-2008
XML - 5
XML’s Relation with HTML and SGML
• What is HTML? HTML (HyperText Markup
Language) is a specific application of SGML
used in the World Wide Web.
• SGML is the "mother tongue", used for
describing thousands of different
document types definitions (DTD)
in many fields of human activity. HTML is just
one of these document types.
SGML
DTD for HTML
HTML Documents
© Minder Chen, 1998-2008
XML - 6
XML’s Relation with HTML and SGML
• XML is an abbreviated version of SGML, to
make it easier for you to define your own
document types, and to make it easier for
programmers to write programs to handle them.
• It omits the more complex and less-used parts
of SGML in return for the benefits of being
easier to write applications, easier to
understand, and more suited to delivery and
interoperability over the Web.
XML is more "SGML--"
rather than "HTML++".
© Minder Chen, 1998-2008
XML - 7
XML
• Extensible Markup Language (XML) 1.0
• W3C Recommendation 10-Feb-98
XML 1.0
Recommendation
XML DTD
XML
Document
© Minder Chen, 1998-2008
A meta-language for defining
XML DTD. XML Schema is a
competing standard.
For a specific type of document
such as a definition of Purchase
Order's data structure. It is used to
validate XML document.
For a specific document such as
a specific Purchase Order.
XML - 8
So, You Need More Than XML…
DTD
Structure
Validation
XML
document
Content
© Minder Chen, 1998-2008
Processing
XSL
Document with
Special Format
(HTML/CSS)
Display
XML - 9
Well-Formed XML
•
•
•
•
•
•
Must start with an XML declaration
Non-empty tags must match and nest properly
Empty tags must end with />
Must have exactly one root element
Tag and attribute names are case-sensitive
Attribute values must be quoted
© Minder Chen, 1998-2008
XML - 10
Rules for Well-Formed XML
• A standard for encoding data
• 4 key differences from HTML
• First: Mandatory Closing Tags
– The set of Tags is unlimited but all container tags
must have end tags. <tag>…</tag>
<TAG>…</TAG>
• Example of legal XML
– <Person>
<Name>Adam Smith</Name>
<Title>General Manager</Title>
<Age>42</Age>
</Person>
© Minder Chen, 1998-2008
XML - 11
Rules for Well-Formed XML
• Second: Proper Element Nesting.
– All tags must be nested correctly. Like HTML, XML can
intermix tags and text, but tags may not overlap each
other.
• Legal XML
<Person>John Smith is an
<role>advocate
</role> for <technology>XML</technology>
</Person>
• Illegal XML
<Person><Name>John </Name>
<KeyPoint><Hd>XML provides a data bus</Hd>
</Person><More>…</More>
</KeyPoint>
© Minder Chen, 1998-2008
XML - 12
Rules for Well-Formed XML
• Third: Double-quote value delimiters
– All attribute values must be enclosed in single or
double quotation marks.
• Legal:
<tag attribute = "value">
or
<tag attribute = 'value'>
• Illegal:
<font size = 6>
<myTAG>
XML tags are case sensitive. <Mytag>
are different
© Minder Chen, 1998-2008
XML - 13
Rules for Well-Formed XML
• Fourth: Single tag elements.
– Singleton tags (called empty element or tags
without content) must be written in an abbreviated
form using special XML syntax.
• Legal:
<BR/>
<HR/>
• <TITLE></TITLE> is equivalent to <TITLE/>
• Illegal:
<BR>
<HR>
© Minder Chen, 1998-2008
XML - 14
So What!
• "You guys look like a bunch of geniuses, and
all you did was say, 'Make the tags balance.' "
--- A Silicon Valley executive
• "There is really not much technology in XML,
and even less that is new. But there are a few
touches that while small, have been crucial."
– XML is text, not binary.
– Superior error-handling
– Internationalization
--- Tim Bray
© Minder Chen, 1998-2008
XML - 15
Sample XML Document
<?xml version="1.0"?>
<PLANT ZONE="3">
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
</PLANT>
A string literal was expected, but no opening quote
character was found. Line 3, Position 13
<PLANT ZONE=3>
------------^
© Minder Chen, 1998-2008
XML - 16
XML Document: Namespaces
• Namespaces provide ways to mix XML tags without chaos
<?xml version="1.0"?>
<!-- both namespace prefixes are available throughout -->
<bk:book xmlns:bk='urn:loc.gov:books'
xmlns:isbn='urn:ISBN:0-395-36341-6'>
<bk:title>Cheaper by the Dozen</bk:title>
<isbn:number>1568491379</isbn:number>
</bk:book>
<?xml version="1.0"?>
<!-- unprefixed element types are from "books" -->
<book xmlns='urn:loc.gov:books'
xmlns:isbn='urn:ISBN:0-395-36341-6'>
<title>Cheaper by the Dozen</title>
<isbn:number>1568491379</isbn:number>
</book>
© Minder Chen, 1998-2008
XML - 17
Creating XML Using XML Notepad
http://www.microsoft.com/downloads/details.aspx?familyid=72d6aa49-787d-4118-ba5f-4f30fe913628&displaylang=en
© Minder Chen, 1998-2008
XML - 18
XML Document: Validation
• You can enforce rules about these tags. Two
kinds of ways to define rules for the document.
These rules can be used to validate an XML
document or used by XML authoring tools to
guide the creation of an XML document.
– Document Type Definition (DTD): This is
used to define a grammar for the tags and
attributes. This syntax is supported, but
deprecated by Microsoft. It uses a special non-XMLbased grammar
– XML Schema (XML-Data): This is a much
richer and more extensible way to describe the
rules for the content of a document and uses
XML itself as a grammar.
© Minder Chen, 1998-2008
XML - 19
XML Document Structure
• Prologue:
– XML declaration
– Document Type Declaration
(DOCTYPE)
– Processing Instructions and
Comments
• Root Element and its child
nodes
• Epilogue:
– Comments and
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM
"bookreview.dtd” >
<book>
<author> Jane Smith </author>
<review>
...
</review>
</book>
<!-- “person” is the root
element.-->
<?imgsize size=“200,200” ?>
– Processing Instructions
© Minder Chen, 1998-2008
XML - 20
Anatomy of a Tag
<H1 ALIGN="CENTER"> XML Tutorial </H1>
<H1 ALIGN="CENTER"> XML Tutorial </H1>
Attribute
Opening tag
Closing
tag
Element
© Minder Chen, 1998-2008
XML - 21
flower2.dtd: Put DTD and XML in One File
<?xml version="1.0"?>
<!DOCTYPE PLANT [
<!ELEMENT PLANT (COMMON, BOTANICAL)>
<!ATTLIST PLANT ZONE CDATA #IMPLIED>
<!ELEMENT COMMON (#PCDATA)>
<!ELEMENT BOTANICAL (#PCDATA)>
]>
<PLANT ZONE="3">
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
</PLANT>
© Minder Chen, 1998-2008
XML - 22
Child Element Occurrence Symbol
Symbol
Meaning
+
Elements with this symbol next to their name
must occur one or more times in the XML
document.
?
Elements with this symbol next to their name
may occur zero times or one time in the XML
document.
*
Elements with this symbol next to their name
may occur zero times, one time, or infinitely
many times in the XML document.
None
© Minder Chen, 1998-2008
One and only one
XML - 23
Element Declaration
• Elements that contain only other elements are
said to have element content
• Elements that contain both other elements and
#PCDATA are said to have mixed content
• For example, the definition for burns might be
<!ELEMENT burns (#PCDATA | quote)*>
• The vertical bar “|” indicates an or relationship,
the asterisk indicates that the content is optional
(may occur zero or more times); therefore, by this
definition, burns may contain zero or more
characters and quote tags, mixed in any order. All
mixed content models must have this form:
#PCDATA must come first, all of the elements
must be separated by vertical bars, and the entire
group must be optional.
© Minder Chen, 1998-2008
XML - 24
Attribute-list Declaration
[52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
[53] AttDef ::= S Name S AttType S DefaultDecl
Example:
<!ATTLIST termdef
id
ID
#REQUIRED
name CDATA
#IMPLIED>
<!ATTLIST list
type (bullets|ordered|glossary) "ordered">
<!ATTLIST form
method CDATA #FIXED "POST">
If an attribute has a default value declared with the #FIXED
keyword, instances of that attribute must match the default
value.
© Minder Chen, 1998-2008
XML - 25
DefaultDecl
Keyword
Implication
#REQUIRED
The element must have a value for the attribute
specified. If the value is not specified, the
document will not be processed
The attribute has a value that does not change
throughout the document.
#FIXED
#IMPLIED
The attribute may have a value declared, or it
could be left empty.
Default Value
This value is specified in place of a keyword in
the <!ATTLIST> tag. If a value is specified in the
document, the default value is replaced.
However, if the document leaves the attribute
value blank, then the default value is assumed.
© Minder Chen, 1998-2008
XML - 26
Attribute
type
Description
CDATA
Indicates to the processor to expect text as the attribute value.
ID
Specifies a unique identifier to the attribute. ID names must start
with a letter or underscore and cannot contain a white space.
NMTOKEN
Specifies that the attribute must start with a letter or an underscore
and cannot contain a white space. However, in the case of a
NMTOKEN, duplicate values are allowed.
Enumerated
This type does not have a keyword. It consists of a list of all
possible values placed inside parentheses and separated by the "|"
symbol, as in the following example:
<!ATTLIST Book Binding (soft | hard) #REQUIRED>
© Minder Chen, 1998-2008
XML - 27
flower3.xml: Plant List
<?xml version="1.0"?>
<!DOCTYPE PLANTLIST [
<!ELEMENT PLANTLIST (PLANT+)>
<!ELEMENT PLANT (COMMON, BOTANICAL)>
<!ELEMENT COMMON (#PCDATA)>
<!ELEMENT BOTANICAL (#PCDATA)>
<!ATTLIST PLANT ZONE (e|w|s|n) "e"
KEY ID
#REQUIRED>
]>
<PLANTLIST>
<PLANT ZONE="w" KEY="A123">
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
</PLANT>
<PLANT ZONE="e" KEY="A124">
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
</PLANT>
</PLANTLIST>
© Minder Chen, 1998-2008
XML - 28
The Node Structure of XML Document
Processing Instruction
Document
Attributes
comment
(Root) Element
Attributes
Document Type
Notations
Entities
childNodes
© Minder Chen, 1998-2008
EntityReference
CDATASection
Element
Processing Instruction
Text
Comment
XML - 29
Well-Formed XML and Valid XML
• Well-Formed XML:
– A well-formed XML document does not
necessarily include a DTD or a
schema.
• Valid XML:
– XML that conforms to the vocabulary
specified in a DTD or schema.
© Minder Chen, 1998-2008
XML - 30
XML- Data Type
flower_schema.xml
<Schema name="PLANTLIST"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schema-microsoft-com:datatypes">
<ElementType name="COMMON" content="textOnly"/>
<ElementType name="BOTANICAL" content="textOnly"/>
<AttributeType name="BESTSELLER" dt:type="enumeration"
dt:values="yes no" default="no" />
<ElementType name="PLANT">
<element type="COMMON"/>
<element type="BOTANICAL"/>
<attribute type="BESTSELLER"/>
</ElementType>
<ElementType name="PLANTLIST" content="eltOnly" model="closed">
<element type="PLANT" minOccurs="1" maxOccurs="*" />
</ElementType>
</Schema>
© Minder Chen, 1998-2008
XML - 31
XSL
• A CSS (Cascading Style Sheet) defines the specification for
an HTML document's presentation and appearance.
• Similarly, XSL (Extensible Style Language) defines the
specification for an XML document’s presentation and
appearance.
• XSL is used to transform XML-based data into HTML or
other presentation formats.
• XSL is a subset of DSSSL (Document Style Semantics and
Specification Language). DSSL is a style language used
primarily with SGML.
• XML is a subset of SGML.
• XSL is the proposed style language for XML documents.
© Minder Chen, 1998-2008
XML - 32
Sample XSL and XML
greeting.xml
<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet href="greeting.xsl" type="text/xsl" ?>
<greeting>
Hello World!
</greeting>
greeting.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<H1> <xsl:value-of /> </H1>
</xsl:template>
</xsl:stylesheet>
© Minder Chen, 1998-2008
XML - 33
XML and XSL
XML deals only with the data structures and contents of a document
XSL specifies rules to convert XML patterns to HTML tags and contents
XML
XML
Web
server
Extensible
Stylesheet
Language
© Minder Chen, 1998-2008
Internet
XSL
XML and XSL
processor
Client-Side
HTML
display
(Browser)
(Browser-side add-on
or building functions)
XML - 34
Integrating XML and XSL: product_xsl3.xml
<?xml version='1.0'?>
<?xml:stylesheet type="text/xsl" href="product_xsl3.xsl" ?>
<PRODUCTLIST>
<PRODUCT>
<ID>html100</ID>
<NAME>Introduction to HTML</NAME>
<PRICE>$200</PRICE>
</PRODUCT>
<PRODUCT>
<ID>xml100</ID>
<NAME>Introduction to XML</NAME>
<PRICE>$250</PRICE>
</PRODUCT>
</PRODUCTLIST>
© Minder Chen, 1998-2008
XML - 35
product_xsl3.xsl
<?xml version="1.0"?>
<HTML xmlns:xsl=
"http://www.w3.org/TR/WD-xsl">
<BODY>
<H1> Course Listing </H1>
<xsl:for-each select="PRODUCTLIST/PRODUCT">
<xsl:value-of select="ID"/> :
<b><xsl:value-of select="NAME"/></b> <br/>
<i> Price: <xsl:value-of select="PRICE"/></i> <hr/>
</xsl:for-each>
</BODY>
</HTML>
© Minder Chen, 1998-2008
XML - 36
Server-side XML & XSL Processing
• Advantages: Browser independent; client only
requires HTML support
• Server is tasked with XSL transformation
© Minder Chen, 1998-2008
http://java.sun.com/xml/
XML - 37
simple.xml
<?xml version='1.0'?>
You don’t need this for the
XML_ServerControl.aspx
<?xml:stylesheet type="text/xsl" href="simple.xsl" ?>
<breakfast-menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian Waffles with plenty of real maple
syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>light Belgian waffles coverred with strawberrys and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>light Belgian waffles coverred with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast-menu>
© Minder Chen, 1998-2008
XML - 38
XML_ServerControl.aspx
© Minder Chen, 1998-2008
XML - 39
BookStore.xml
<Bookstore>
<genre name="Business">
<book ISBN="BU1032" Title="The Busy Executive's Database Guide" Price="19.99">
<chapter num="1" name="Introduction">
Abstract...
</chapter>
<chapter num="2" name="Body">
Abstract...
</chapter>
<chapter num="3" name="Conclusion">
Abstract...
</chapter>
</book>
<book ISBN="BU2075" Title="You Can Combat Computer Stress!" Price="2.99">
<chapter num="1" name="Introduction">
Abstract...
</chapter>
<chapter num="2" name="Body">
Abstract...
</chapter>
<chapter num="3" name="Conclusion">
Abstract...
</chapter>
</book>
<book ISBN="BU7832" Title="Straight Talk About Computers" Price="19.99">
<chapter num="1" name="Introduction">
Abstract...
</chapter>
<chapter num="2" name="Body">
Abstract...
</chapter>
<chapter num="3" name="Conclusion">
Abstract...
</chapter>
</book>
</genre>
</Bookstore>
© Minder Chen, 1998-2008
XML - 40
BookList.aspx
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>DataList Bound to XML</title></head><body>
<form runat="server">
<h1>Bookstore: Business</h1>
<asp:XmlDataSource id="MySource" DataFile="~/App_Data/Bookstore.xml"
XPath="Bookstore/genre[@name='Business']/book" runat="server"/>
<asp:DataList id="MyDataList" DataSourceId="MySource" runat="server">
<ItemTemplate>
<table><tr><td>
<img alt="Cover Image" src='<%#"images/" + Eval("ISBN") + ".gif"%>'></td>
<td><h4><%# Eval("Title") %></h4>
<b>ISBN:</b> <%# Eval("ISBN") %><br>
<b>Price:</b> <%# Eval("Price") %><br></td>
</tr></table>
</ItemTemplate>
</asp:DataList>
</form></body></html>
•
•
XPath: http://msdn2.microsoft.com/en-us/library/ms256471.aspx
http://quickstarts.asp.net/QuickStartv20/aspnet/samples/data/DataListXml_vb.aspx
© Minder Chen, 1998-2008
XML - 41
simple.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0“
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<BODY STYLE="font-family:Arial, helvetica, sans-serif; font-size:12pt; background-color:#EEEEEE">
<xsl:for-each select="breakfast-menu/food">
<DIV STYLE="background-color:teal; color:white; padding:4px">
<SPAN STYLE="font-weight:bold; color:white">
<xsl:value-of select="name"/>
</SPAN>
- <xsl:value-of select="price"/>
</DIV>
<DIV STYLE="margin-left:20px; margin-bottom:1em; font-size:10pt">
<xsl:value-of select="description"/>
<SPAN STYLE="font-style:italic">
(<xsl:value-of select="calories"/> calories per serving)
</SPAN>
</DIV>
</xsl:for-each>
</BODY>
</html>
</xsl:template>
</xsl:stylesheet>
© Minder Chen, 1998-2008
XML - 42
XML_ServerControl.aspx
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Xml ID="Xml1" runat="server"
DocumentSource="Menu.xml"
TransformSource="Menu.xsl" ></asp:Xml>
</div>
</form>
</body>
</html>
© Minder Chen, 1998-2008
XML - 43
RSS: Really Simple Syndication
<rss version="0.91">
<channel>
<title>XML.com</title>
<link>http://www.xml.com/</link>
<description>XML.com features a rich mix of information and services for the XML
community.</description>
<language>en-us</language>
<item>
<title>Normalizing XML, Part 2</title>
<link>http://www.xml.com/pub/a/2002/12/04/normalizing.html</link>
<description>In this second and final look at applying relational normalization techniques to
W3C XML Schema data modeling, Will Provost discusses when not to normalize, the scope of
uniqueness and the fourth and fifth normal forms.</description>
</item>
<item>
<title>The .NET Schema Object Model</title>
<link>http://www.xml.com/pub/a/2002/12/04/som.html</link>
<description>Priya Lakshminarayanan describes in detail the use of the .NET Schema Object
Model for programmatic manipulation of W3C XML Schemas.</description>
</item>
<item>
<title>SVG's Past and Promising Future</title>
<link>http://www.xml.com/pub/a/2002/12/04/svg.html</link>
<description>In this month's SVG column, Antoine Quint looks back at SVG's journey through
2002 and looks forward to 2003.</description>
</item>
</channel>
</rss>
© Minder Chen, 1998-2008
XML - 44
RSS_GenerateSimple.aspx
<%@ Page Language="VB" ContentType="text/XML" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDB" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.UI" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Text" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Data.Common" %>
<%@ OutputCache Duration="300" VaryByParam="None" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Response.ContentType = "text/xml"
GenerateRSS()
Response.End()
End Sub
Public Function GetArticles() As OleDbDataReader
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
conn = New OleDbConnection()
conn.ConnectionString = _
System.Configuration.ConfigurationManager.ConnectionStrings("RSSConnString").ConnectionString
cmd = conn.CreateCommand()
cmd.CommandText = "Select Title, Link, Description, PublishDate from Articles"
cmd.CommandType = CommandType.Text
conn.Open()
Return cmd.ExecuteReader(CommandBehavior.CloseConnection)
End Function
© Minder Chen, 1998-2008
XML - 45
Continued…
Private Sub GenerateRSS()
Dim reader As OleDbDataReader
' Create XmlWriter which will generate RSS output
Dim xmlOut as StringBuilder = New StringBuilder()
xmlOut.Append("<?xml version='1.0' encoding='ISO-8859-1'?>")
xmlOut.Append("<rss version='2.0'>")
xmlOut.Append("<channel>")
xmlOut.Append("<title>XML.com</title>")
xmlOut.Append("<link>http://www.xml.com/</link>")
xmlOut.Append("<description>XML.com features a rich mix of information and services for the
XML community.</description>")
reader = GetArticles()
While (reader.Read())
xmlOut.Append("<item>")
xmlOut.Append("<title>" & reader("Title").ToString() & "</title>")
xmlOut.Append("<link>" & reader("Link").ToString() & "</link>")
xmlOut.Append("<description>" & reader("description").ToString() & "</description>")
xmlOut.Append("<pubDate>" & DateTime.Parse(reader("PublishDate")).ToString() &
"</pubDate>")
xmlOut.Append("</item>")
End While
xmlOut.Append("</channel>")
xmlOut.Append("</rss>")
Response.Write(xmlOut.ToString())
reader.Close()
End Try
End Sub
</script>
© Minder Chen, 1998-2008
XML - 46
RSS_Feed.aspx
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub ddRSS_SelectedIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim DataFileName as String
DataFileName = ddRSS.SelectedValue
If DataFileName.Substring(0, 7).ToLower = _
"http://" or DataFileName.Substring(DataFileName.Length-3, 3).ToLower = "xml" Then
xdsRSS.DataFile = ddRSS.SelectedValue
Else
DIm origin as Uri = HttpContext.Current.Request.Url
DIm relative as String = ddRSS.SelectedValue
DIm newUri as URI = new Uri(origin, relative)
xdsRSS.DataFile = newUri.ToString()
End If
End Sub
</script>
© Minder Chen, 1998-2008
XML - 47
Continued…
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<h2>Using the XmlDataSource Control</h2>
<div>
<b>RSS Feed:&nbsp; </b>
<asp:DropDownList ID="ddRSS" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddRSS_SelectedIndexChanged" >
<asp:ListItem Value="">Select One:</asp:ListItem>
<asp:ListItem Value="~/RSS/cnn_tech.xml">CNN Technologies News</asp:ListItem>
<asp:ListItem Value="~/RSS/XMLForASP.NET.xml">XML for ASP.NET RSS</asp:ListItem>
<asp:ListItem Value="~/RSS/RSS_Sample.xml">RSS Sample</asp:ListItem>
<asp:ListItem Value="http://msdn.microsoft.com/asp.net/rss.xml">MSDN ASP.NET
RSS</asp:ListItem>
<asp:ListItem Value="~/RSS/XMLDB.xml">Static RSS generated from RSS.mdb
</asp:ListItem>
<asp:ListItem Value="RSS_Generate.aspx">1a. Relative URL Dynamic RSS generated
from RSS.mdb - Use xmlWriter</asp:ListItem>
<asp:ListItem Value="RSS_GenerateSimple.aspx">1b. Relative URL Dynamic RSS
generated from RSS.mdb -- Do not use xmlWriter </asp:ListItem>
<asp:ListItem Value="http://localhost:4542/XMLTutor/RSS_Generate.aspx">2. Full URL
Dynamic RSS generated from RSS.mdb </asp:ListItem>
<asp:ListItem Value="http://www.xmlforasp.net/XML/RssGenerator.aspx">Reset to
original</asp:ListItem>
</asp:DropDownList>
© Minder Chen, 1998-2008
XML - 48
Continued…
<br />
<br />
<asp:DataList ID="dlRSS" runat="server" BackColor="White"
BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Horizontal" EnableViewState="False" DataSourceID="xdsRSS">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True"
ForeColor="#F7F7F7" />
<AlternatingItemStyle BackColor="#F7F7F7" />
<ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<ItemTemplate>
<a href='<%# XPath("link") %>' style="text-decoration:none;"><%#
XPath("title") %></a>
</ItemTemplate>
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
</asp:DataList>
<asp:XmlDataSource ID="xdsRSS" runat="server" XPath="/rss/channel/item"
DataFile="http://www.xmlforasp.net/XML/RssGenerator.aspx"
CacheDuration="60"></asp:XmlDataSource>
</div>
</form>
</body>
</html>
© Minder Chen, 1998-2008
XML - 49
Existing methods - EDI messages
• UN standard format (EDIFACT) or X.12
• Compact strings, with numeric qualifiers. Strict limitation on the
number of characters and position of data in a document.
• Example:
• UNH+900576+ORDERS:D:93A:UN:EAN007’BGM+220+H940568’DTM
+137:19940201:102’
NAD+BY+5412345000176::9’NAD+SU+4012345000094::9’LIN+2’PIA
+5_1857990455:IB’
IMD+F+BAU+:::Farell J G’IMD+F+BTI+:::The Singapore
Grip’QTY+21:1’
PRI+XXX:7.99’UNS+S’CNT+2:2’UNT+15+900576’
• Rules for data type control
© Minder Chen, 1998-2008
XML - 50
EDI and XML
EDI
VAN
EDI
XML
© Minder Chen, 1998-2008
EDI
XML
XML - 51
BizTalk
© Minder Chen, 1998-2008
XML - 52
Descargar

Document