《The Object-Oriented Thought Process》读书笔记9

11 Objects and Portable Data: XML

XML is astandard mechanism for defining and transporting data between potentially

disparate systems.

Portable Data

XML providesstandards to move data in a variety of ways. Often we can think of data asmoving vertically and horizontally.The term vertical means that data is meant to move through multipleindustry groups. Horizontalapplications are specific to a particular industry, such as retail ortransportation.

Figure 11.1 XML across industries.

Hospitality

英 [ˌhɒspɪˈtæləti] 美 [ˌhɑspɪˈtæləti]

n. 殷勤好客;招待,款待;(气候,环境等的)宜人,适宜

The Extensible Markup Language (XML)

HTML (HypertextMarkup Language).

Both XML andHTML are descendants of SGML, the Standard Generalized Markup Language.

XML is notproprietary and the World Wide Web Consortium (W3C) is the organization thatproposes recommendations and that promotes the distribution of its standards.

XML Versus HTML

HTML presentsdata, and XML describes the data.

Document Type Definition (DTD)

The DTD is where you define the tagsthat describe your data.

Valid Document

You are not required to use a DTD.However, using a DTD provides a great benefit to validating XML documents.

For example, ifyou are creating a purchase order system, you might want to create a tag called<PurchaseOrder> in the DTD. If you then misspell the tag like this:

<PurchasOrder>,this problem will be detected, and the document will be flagged as invalid.

XML and Object-Oriented Languages

Alpha Company, adepartment store, uses an Oracle database, and Beta Company, a vacuum machinemanufacturer, uses a SQL Server database.Alpha Company wants to purchase somevacuum cleaners from Beta Company for its inventory.

Proprietary Solutions

Alpha Company can create an XML specification to which all its supplierscan connect.

Figure 11.2 Application-to-application data transfer.

Sharing Data Between Two Companies

Validating the Document with the Document Type Definition(DTD)

supplier.dtd

<!-- DTD for supplier document -->

<!ELEMENT supplier ( name, address)>

<!ELEMENT name ( companyname)>

<!ELEMENT companyname ( #PCDATA)>

<!ELEMENT address ( street+, city,state, zip)>

<!ELEMENT street ( #PCDATA)>

<!ELEMENT city ( #PCDATA)>

<!ELEMENT state ( #PCDATA)>

<!ELEMENT zip ( #PCDATA)>

 

The first line is an XMLcomment.

<!ELEMENT supplier ( name, address,product)>

This tag defines an element called supplier.

The <companyname> element is then defined to be a data elementdesignated by

#PCDATA.

<!ELEMENTcompanyname ( #PCDATA)>

PCDATA

PCDATA stands for ParsedCharacter Data and is simply standard character information

parsedfrom the text file.

Integrated the DTD into the XML Document

supplier.xml

<?xml version="1.0"encoding="utf-8" standalone="no"?>

<?xml-stylesheethref="supplier.css" type="text/css" ?>

<!DOCTYPE supplier SYSTEM"supplier.dtd">

<!-- The XML data -->

<supplier>

<name>

<companyname>The BetaCompany</companyname>

</name>

<address>

<street>12000 OntarioSt</street>

<city>Cleveland</city>

<state>OH</state>

<zip>24388</zip>

</address>

</supplier>

 

XML Notepad

XML Notepad can help usunderstand the structure of an XML document.

 

Using Cascading Style Sheet

supplier.css

companyname{font-family:Arial, sans-serif;

font-size:24;

color:blue;

display:block;}

street {font-family:¡±Times New Roman¡±,serif;

font-size:12;

color:red;

display:block;}

city {font-family:¡±Courier New¡±, serif;

font-size:18;

color:black;

display:block;}

state {font-family:¡±Tahoma¡±; serif;

font-size:16;

color:gray;

display:block;}

zip {font-family:¡±Arial Black¡±,sans-serif;

font-size:6;

color:green;

display:block;}

 

 

Figure 11.11 The XML document using a cascading stylesheet.

Conclusion

In thischapter,we discussed many aspects of XML and why it is a very importanttechnology within the IT community

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值