﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-Favor Soup | 反胃书屋-随笔分类-XML相关</title><link>http://www.cnitblog.com/dickznew/category/5061.html</link><description>斯是陋室，惟吾德馨。</description><language>zh-cn</language><lastBuildDate>Sun, 02 Oct 2011 02:31:04 GMT</lastBuildDate><pubDate>Sun, 02 Oct 2011 02:31:04 GMT</pubDate><ttl>60</ttl><item><title>XML Beginner notes (2)</title><link>http://www.cnitblog.com/dickznew/archive/2007/04/04/25159.html</link><dc:creator>D主</dc:creator><author>D主</author><pubDate>Wed, 04 Apr 2007 08:37:00 GMT</pubDate><guid>http://www.cnitblog.com/dickznew/archive/2007/04/04/25159.html</guid><wfw:comment>http://www.cnitblog.com/dickznew/comments/25159.html</wfw:comment><comments>http://www.cnitblog.com/dickznew/archive/2007/04/04/25159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/dickznew/comments/commentRss/25159.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/dickznew/services/trackbacks/25159.html</trackback:ping><description><![CDATA[<p><span style="FONT-FAMILY: Arial">XML Schema is an XML-based alternative to DTD.<br>An XML schema describes the structure of an XML document.<br>The XML Schema language is also referred to as XML Schema Definition (XSD).</span><br><br></p>
<h2><span style="COLOR: #000000">What is an XML Schema?<br></span></h2>
<p><span style="FONT-FAMILY: Arial">The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.</span><br><span style="FONT-FAMILY: Arial">An XML Schema:</span></p>
<ul>
    <li><span style="FONT-FAMILY: Arial">defines elements that can appear in a document </span>
    <li><span style="FONT-FAMILY: Arial">defines attributes that can appear in a document&nbsp; </span>
    <li><span style="FONT-FAMILY: Arial">defines which elements are child elements&nbsp; </span>
    <li><span style="FONT-FAMILY: Arial">defines the order of child elements </span>
    <li><span style="FONT-FAMILY: Arial">defines the number of child elements </span>
    <li><span style="FONT-FAMILY: Arial">defines whether an element is empty or can include text </span>
    <li><span style="FONT-FAMILY: Arial">defines data types for elements and attributes&nbsp; </span>
    <li><span style="FONT-FAMILY: Arial">defines default and fixed values for elements and attributes</span> </li>
</ul>
<p><span style="FONT-FAMILY: Arial"><strong>XSL</strong></span><br><br><span style="FONT-FAMILY: Arial">It started with XSL and ended up with XSLT, XPath, and XSL-FO.</span></p>
<h2><span style="COLOR: #000000">It Started with XSL<br></span></h2>
<p style="FONT-FAMILY: Arial">XSL stands for EXtensible Stylesheet Language.</p>
<p style="FONT-FAMILY: Arial">The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based Stylesheet Language.<br></p>
<h2><span style="COLOR: #000000">CSS = HTML Style Sheets</span><br></h2>
<p style="FONT-FAMILY: Arial">HTML uses predefined tags and the meaning of the tags are well understood. <br>The &lt;table&gt; element in HTML defines a table - and a browser knows how to display it. <br>Adding styles to HTML elements is simple. Telling a browser to display an element in a special font or color, is easy with CSS. <br></p>
<h2><span style="COLOR: #000000"><br>XSL = XML Style Sheets</span><br></h2>
<p style="FONT-FAMILY: Arial">XML does not use predefined tags (we can use any tag-names we like), and the meaning of these tags are not well understood.<br>The &lt;table&gt; element in HTML defines a table - and a browser knows how to display it. <br>Adding styles to HTML elements is simple. Telling a browser to display an element in a special font or color, is easy with CSS. <br><br></p>
<h2><span style="COLOR: #000000">XSL - More Than a Style Sheet Language</span> <br></h2>
<p><span style="FONT-FAMILY: Arial">XSL consists of three parts:</span></p>
<ul>
    <li><span style="FONT-FAMILY: Arial">XSLT - a language for transforming XML documents </span>
    <li><span style="FONT-FAMILY: Arial">XPath - a language for navigating in XML documents </span>
    <li><span style="FONT-FAMILY: Arial">XSL-FO - a language for formatting XML documents </span></li>
</ul>
<p><br>&nbsp;</p>
<img src ="http://www.cnitblog.com/dickznew/aggbug/25159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/dickznew/" target="_blank">D主</a> 2007-04-04 16:37 <a href="http://www.cnitblog.com/dickznew/archive/2007/04/04/25159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>XML Beginner notes (1)</title><link>http://www.cnitblog.com/dickznew/archive/2007/04/04/25156.html</link><dc:creator>D主</dc:creator><author>D主</author><pubDate>Wed, 04 Apr 2007 08:20:00 GMT</pubDate><guid>http://www.cnitblog.com/dickznew/archive/2007/04/04/25156.html</guid><wfw:comment>http://www.cnitblog.com/dickznew/comments/25156.html</wfw:comment><comments>http://www.cnitblog.com/dickznew/archive/2007/04/04/25156.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/dickznew/comments/commentRss/25156.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/dickznew/services/trackbacks/25156.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: black thin solid; PADDING-RIGHT: 10px; BORDER-TOP: black thin solid; PADDING-LEFT: 10px; FONT-SIZE: 13px; PADDING-BOTTOM: 10px; BORDER-LEFT: black thin solid; PADDING-TOP: 10px; BORDER-BOTTOM: black thin solid; FONT-FAMILY: Arial; BACKGROUND-COLOR: #e0e0e0">XML was designed to describe data and to focus on what data is while HTML was designed to display data and to focus on how data looks. <br>XML was designed to describe data, its tags are not predefined. You must define your own tags. XML uses a Document Type Definition (DTD) or an XML Schema to describe the data. <br>Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store and to send information.</div>
<br>
<div style="BORDER-RIGHT: black thin solid; PADDING-RIGHT: 10px; BORDER-TOP: black thin solid; PADDING-LEFT: 10px; FONT-SIZE: 13px; PADDING-BOTTOM: 10px; BORDER-LEFT: black thin solid; PADDING-TOP: 10px; BORDER-BOTTOM: black thin solid; FONT-FAMILY: Arial; BACKGROUND-COLOR: #e0e0e0"><strong>XML Namespaces provide a method to avoid element name conflicts.</strong><br>Since element names in XML are not predefined, a name conflict will occur when two different documents use the same element names.<br><strong>EXAMPLES:</strong> <br>This XML document carries information in a table:
<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 12px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; FONT-FAMILY: courier new">&lt;table&gt;<br>&nbsp;&nbsp;&nbsp;&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;Apples&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;Bananas&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<br>&lt;/table&gt;</div>
This XML document carries information about a table (a piece of furniture):
<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 12px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; FONT-FAMILY: courier new">&lt;table&gt;<br>&nbsp;&nbsp;&nbsp; &lt;name&gt;African Coffee Table&lt;/name&gt;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;width&gt;80&lt;/width&gt;&nbsp;<br>&nbsp;&nbsp;&nbsp; &lt;length&gt;120&lt;/length&gt;<br>&lt;/table&gt;</div>
If these two XML documents were added together, there would be an element name conflict because both documents contain an element with different content and definition. <br><strong><br>Solving Name Conflicts Using a Prefix</strong> <br>This XML document carries information in a table:
<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 12px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; FONT-FAMILY: courier new">
<pre>&lt;h:table&gt;<br>   &lt;h:tr&gt;<br>   &lt;h:td&gt;Apples&lt;/h:td&gt;<br>   &lt;h:td&gt;Bananas&lt;/h:td&gt;<br><br>   &lt;/h:tr&gt;<br>&lt;/h:table&gt;</pre>
</div>
This XML document carries information about a piece of furniture:
<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 12px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; FONT-FAMILY: courier new">
<pre>&lt;f:table&gt;<br>   &lt;f:name&gt;African Coffee Table&lt;/f:name&gt;<br>   &lt;f:width&gt;80&lt;/f:width&gt;<br><br>   &lt;f:length&gt;120&lt;/f:length&gt;<br>&lt;/f:table&gt;</pre>
</div>
Now there will be no name conflict because the two documents use a different name for their &lt;table &gt; element ( &lt;h:table &gt; and &lt; f:table &gt;). By using a prefix, we have created two different types of &lt; table &gt; elements. <br><br>
<h2><span style="COLOR: #000000; FONT-FAMILY: Arial">Using Namespaces<br></span></h2>
<p>This XML document carries information in a table:<br></p>
<table class=ex cellSpacing=0 width="100%" border=1>
    <tbody>
        <tr>
            <td>
            <pre>&lt;h:table xmlns:h="http://www.w3.org/TR/html4/"&gt;<br>   &lt;h:tr&gt;<br><br>   &lt;h:td&gt;Apples&lt;/h:td&gt;<br>   &lt;h:td&gt;Bananas&lt;/h:td&gt;<br>   &lt;/h:tr&gt;<br>&lt;/h:table&gt;</pre>
            </td>
        </tr>
    </tbody>
</table>
<p>This XML document carries information about a piece of furniture:<br></p>
<table class=ex cellSpacing=0 width="100%" border=1>
    <tbody>
        <tr>
            <td>
            <pre>&lt;f:table xmlns:f="http://www.w3schools.com/furniture"&gt;<br>   &lt;f:name&gt;African Coffee Table&lt;/f:name&gt;<br>   &lt;f:width&gt;80&lt;/f:width&gt;<br>   &lt;f:length&gt;120&lt;/f:length&gt;<br><br>&lt;/f:table&gt;</pre>
            </td>
        </tr>
    </tbody>
</table>
<p>Instead of using only prefixes, we have added an xmlns attribute to the &lt;table&gt; tag to give the prefix a qualified name associated with a namespace.<br><br></p>
<h2><span style="COLOR: #000000; FONT-FAMILY: Arial">The XML Namespace (xmlns) Attribute<br></span></h2>
<p>The XML namespace attribute is placed in the start tag of an element and has the following syntax:<br></p>
<p>
<table class=ex cellSpacing=0 width="100%" border=1>
    <tbody>
        <tr>
            <td>
            <pre>xmlns:<em>namespace-prefix</em>="<em>namespaceURI</em>"</pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p>When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace.<br></p>
<p><strong>Note</strong> that the address used to identify the namespace is not used by the parser to look up information. <strong>The only purpose is to give the namespace a unique name.</strong> However, very often companies use the namespace as a pointer to a real Web page containing information about the namespace.<br></p>
<h2>&nbsp;</h2>
<h2><span style="COLOR: #000000; FONT-FAMILY: Arial">Uniform Resource Identifier (URI)</span><br></h2>
<p>A <strong>Uniform Resource Identifier</strong> (URI) is a string of characters which identifies an Internet Resource. <br>The most common URI is the <strong>Uniform Resource Locator</strong> (URL) which identifies an Internet domain address. Another, not so common type of URI is the <strong>Universal Resource Name</strong> (URN). In our examples we will only use URLs.<br><br></p>
<h2><span style="COLOR: #000000; FONT-FAMILY: Arial">Default Namespaces<br></span></h2>
<p>Defining a default namespace for an element saves us from using prefixes in all the child elements. It has the following syntax:<br></p>
<p>
<table class=ex cellSpacing=0 width="100%" border=1>
    <tbody>
        <tr>
            <td>
            <pre>xmlns="<em>namespaceURI</em>"</pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p>This XML document carries information in a table:<br></p>
<p>
<table class=ex cellSpacing=0 width="100%" border=1>
    <tbody>
        <tr>
            <td>
            <pre>&lt;table xmlns="http://www.w3.org/TR/html4/"&gt;<br><br>   &lt;tr&gt;<br>   &lt;td&gt;Apples&lt;/td&gt;<br>   &lt;td&gt;Bananas&lt;/td&gt;<br>   &lt;/tr&gt;<br>&lt;/table&gt;</pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p>This XML document carries information about a piece of furniture:<br></p>
<p>
<table class=ex cellSpacing=0 width="100%" border=1>
    <tbody>
        <tr>
            <td>
            <pre>&lt;table xmlns="http://www.w3schools.com/furniture"&gt;<br>   &lt;name&gt;African Coffee Table&lt;/name&gt;<br>   &lt;width&gt;80&lt;/width&gt;<br><br>   &lt;length&gt;120&lt;/length&gt;<br>&lt;/table&gt;</pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
</div>
<img src ="http://www.cnitblog.com/dickznew/aggbug/25156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/dickznew/" target="_blank">D主</a> 2007-04-04 16:20 <a href="http://www.cnitblog.com/dickznew/archive/2007/04/04/25156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>