XML - 管理数据交换/Exchanger XML Lite
上一章 | 下一章 |
← XQuery | XML 和 JDBC → |
Cladonia 免费提供一个 xml 编辑器,可在 http://www.exchangerxml.com/ 免费用于非商业用途,无需注册即可下载。
这是一个基于 Java 的产品,可在所有平台上运行,包括 Windows、Linux、Mac OSX 和 UNIX。
(注意:如果您需要用于商业用途的 XML 编辑器,您可以在 http://www.exchangerxml.com 免费试用 30 天 Exchanger XML Professional)
以下说明将逐步引导您完成与 XML - 管理数据交换/单个实体 章中相同的项目。
1) 打开 Exchanger XML Lite
2) 点击
-Project -New Project : a "New Project" folder will appear in the project folder window
3) 在“新项目”标题上键入“TourGuide”,将新项目的名称更改为 TourGuide。
1) 点击
-File -New -For Type -Scroll to "XML Schema Definition" and highlight it -OK
2) Exchanger 会自动在文件中为您添加开始和结束标签,但是,对于我们的示例,请删除这些自动标签,并将以下代码复制粘贴到文件中
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified"> <!-- Tour Guide --> <!--The tourGuide element is defined as a complex element type, i.e. it has embedded elements.--> <xsd:element name="tourGuide"> <xsd:complexType> <xsd:sequence> <!--The minimum number of times an element can occur is set using minOccurs (default is 1) and an unlimited number of times an element can occur maxOccurs=”unbounded”.--> <xsd:element name="city" type="cityDetails" minOccurs = "1" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> </xsd:element> <!-- City --> <!--City is declared an element of named complex type --> <!--<xsd:complexType begins the declaration of a complex type, ”cityDetails” identifies the complex type. This is NOT the name of the element. This complex type definition may be used in the declarations of more than one element.--> <xsd:complexType name="cityDetails"> <!--Schema element sequence {13} specifies that the child elements must appear in the order specified.--> <xsd:sequence> <!--<xsd:element begins the declaration of an element of simple type. ”cityName” is the name of the element being declared (in the XML document it will look something like: <cityName> ) and ”xsd:string” is the data type of the element.--> <xsd:element name="cityName" type="xsd:string"/> <xsd:element name="adminUnit" type="xsd:string"/> <xsd:element name="country" type="xsd:string"/> <xsd:element name="population" type="xsd:integer"/> <xsd:element name="area" type="xsd:integer"/> <xsd:element name="elevation" type="xsd:integer"/> <xsd:element name="longitude" type="xsd:decimal"/> <xsd:element name="latitude" type="xsd:decimal"/> <xsd:element name="description" type="xsd:string"/> <xsd:element name="history" type="xsd:string"/> <!--Closing of tags. Note: these should not overlap.--> </xsd:sequence> </xsd:complexType> </xsd:schema>
3) 点击绿色复选标记进行验证,并点击棕色复选标记检查是否格式良好。这些可以在工具栏中找到:
(注意:请确保在您粘贴的文本之前消除任何“空白”,否则您在验证时可能会出现错误。)
4) 点击
-File -Save -"city.xsd"
5) 右键点击
-"TourGuide" project folder -Add File -click on "city.xsd" -open (Note: Now the project "TourGuide" should contain one file, "city.xsd".)
1) 点击
-File -New -For Type -Scroll to "XML StyleSheet Language" and highlight it -OK
2) 删除出现的任何自动标签,并将以下代码剪切粘贴到文件中
<?xml version="1.0" encoding="UTF-8"?> <!--<xsl:stylesheet> declares start of stylesheet and identifies the version number and the official W3C namespace.--> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <!--<xsl:template> defines the start of a template and contains rules to apply when a specified node is matched. The match attribute is used to associate (match) the template with an XML element, in this case the root (/), or whole branch, of the XML source document. The XSL looks for the root match and then outputs the HTML.--> <xsl:template match="/"> <!--The contents of the template element are placed in the output stream of HTML that the browser will be able to interpret.--> <html> <head> <title>Tour Guide</title> </head> <body> <h2>Cities</h2> <xsl:apply-templates select="tourGuide"/> </body> </html> </xsl:template> <xsl:template match="tourGuide"> <xsl:for-each select="city"> <xsl:text>City: </xsl:text> <!--<xsl:value-of> extracts the value of the selected node/XML element and adds it to the output stream--> <xsl:value-of select="cityName"/> <br/> <xsl:text>Population: </xsl:text> <xsl:value-of select="population"/> <br/> <xsl:text>Country: </xsl:text> <xsl:value-of select="country"/> <br/> <br/> </xsl:for-each> <!--<xsl:for-each> can be used to loop through each node in a specified node set and add them to the output--> </xsl:template> </xsl:stylesheet>
3) 点击绿色复选标记进行验证,并点击棕色复选标记检查是否格式良好。(注意:请确保在您粘贴的文本之前消除任何“空白”,否则您在验证时可能会出现错误。)
4) 点击
-File -Save As -"city.xsl"
5) 右键点击
-"TourGuide" project folder -Add File -"city.xsl" -open
(Note: Now the project "TourGuide" contains two files, "city.xsd", and "city.xsl".)
thumhttp://xpressvds.blogspot.com/bnail
1) 点击
-File -New -Default XML Document -OK
2) 删除出现的任何自动标签,并将以下代码复制粘贴
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="city.xsl" type="text/xsl"?> <!--The following declaration identifies the root element of the document (tourGuide) and the schema file (city.xsd) using xsi=schemaLocation--> <tourGuide> xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='city.xsd'> <!--The definition of the first city--> <city> <cityName>Belmopan</cityName> <adminUnit>Cayo</adminUnit> <country>Belize</country> <population>11100</population> <area>5</area> <elevation>130</elevation> <longitude>88.44</longitude> <latitude>17.27</latitude> <description>Belmopan is the capital of Belize</description> <history>Belmopan was established following the devastation of the former capitol, Belize City, by Hurricane Hattie in 1965. High ground and open space influenced the choice and ground-breaking began in 1966. By 1970 most government offices and operations had already moved to the new location. </history> </city> <!--the definition of the second city--> <city> <cityName>Kuala Lumpur</cityName> <adminUnit>Selangor</adminUnit> <country>Malaysia</country> <population>1448600</population> <area>243</area> <elevation>111</elevation> <longitude>101.71</longitude> <latitude>3.16</latitude> <description>Kuala Lumpur is the capital of Malaysia and the largest city in the nation</description> <history>The city was founded in 1857 by Chinese tin miners and perseded Klang. In 1880 the British government transferred their headquarters from Klang to Kuala Lumpur, and in 1896 it became the capital of Malaysia. </history> </city> <!--The closing of the root element tag--> </tourGuide>
3) 点击绿色复选标记进行验证,并点击棕色复选标记检查是否格式良好。(注意:请确保在您粘贴的文本之前消除任何“空白”,否则您在验证时可能会出现错误。)
(Also NOTE: You may need to select -Schema -Infer XML Schema -then choose city.xsd in order to validate the xml file.)
4) 点击
-File -Save As -city.xml
5) 右键点击
-TourGuide -Add File -"city.xml" -open (Note: Now project "TourGuide" should contain three files, "city.xsd","city.xsl", and "city.xml".)
1) 打开 city.xml 文件。
2) 点击
-Transform -Execute Simple XSLT -Current Document -OK
-XSL input -From URl -pick city.xsl -open -OK
-Use Default Processor -OK Note: the window should say "Transformation Complete"
Now you may close this window and follow step 3 to get the results.
3) 点击
-Tools -Start Browser Note: Results should look like this: