XML is incredibly diverse and includes a host of othertechnologies including XPointer, XLink, and Resource Description Framework (RDF).
we are defining Web Services to be built onXML, SOAP, WSDL, and UDDI over a transport protocol such as HTTP. Thisdefinition will become clearer as our discussions progressXML Parsers
Processing an XML document requires the use of an XML parser, a program that can decompose the XML document into its individual elements. There are two major categories of XML parsers:Document Object Model (DOM) and Simple API for XML (SAX).
DOM解析主要有两个缺点:
1:xml需要全部一次性加载到内存中,如果xml足够大,将导致很大的性能开销,性能会很低。
2:因为xml是跨语言独立的,应用非常普遍,因此许多常用的编程语言需要更多的步骤去处理xml,因为不是语言特定的。例如java采用 JDOM解析。
SAX解析:
sax解析是基于事件的解析,sax解析依赖于事件注册,每一个事件句柄是一个处理特定任务的代码块,SAX解析的主要优点就是不需要一次性的把xml的dom文档加载到内存中。 调用事件句柄xml作为一种数据流处理,sax解析比dom更容易工作。
也有两个缺点
1:一旦xml被读后,内存中就不在有xml的内容了,如果需要额外的处理需要再进行解析。
2:SAX解析不能修改xml文档的内容。
XML需要特定的格式:所以 一个格式良好的xml才能进行解析,否则DOM和SAX拒绝解析格式不完整的xml:
怎样才能保证xml格式正确呢!
DTDs and Schemas是两个约束xml的定义。
XML Namespaces
An enterprise system consists of dozens if not hundreds of XML documents. As these XML documents are merged from other sources, inevitably there will be duplicate element names. This can cause problems because each element must have a unique name. XML resolves this name collision issue through the use of namespaces (Java provides a similar feature through packages). Each element is prefixed with a namespace and therefore has to be unique only for that given namespace rather than globally. In practice, the prefix is usually the name of the company, although any Uniform Resource Locator (URL) will do.2 Thus, an element name is composed of two parts: the namespace and the name of the element. By qualifying the name of each element with a qualifier, the likelihood of a name collision is greatly reduced. Consider the file system, for example. For a given directory, a filename must be unique. However, there can be multiple identical filenames as long as each exists in a different directory. In a sense, the directory provides the namespace and qualifies the filename to resolve filename conflicts.
以上是对xml命名空间的解释,简单的来说就是防止元素命名冲突,就想java的 包名,防止类名冲突一样。
Service-Oriented Access Protocol (SOAP)


Migrating from XML to SOAP(转化xml到soap)
转化xml到soap是一个很简单的过程,转化包括以下步骤:<?xml version="1.0" encoding="UTF-8"?>
<Order>
<Customer>
<name>John Doe</name>
<street>1111 AnyStreet</street>
<city>AnyTown</city>
<state>GA</state>
<zip>10000</zip>
/Customer>
</Order>
转化为soap后为(为了更加直观,http片段被省去)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmnls:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope"
xmnls:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmnls:xsi="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Header>
. . . [optional header information]
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<Order>
<Customer>
<name>John Doe</name>
<street>1111 AnyStreet<street>
<city>AnyTown</city>
<state>GA<state>
<zip>10000</zip>
</Customer>
</Order>
<SOAP-ENV:Body>
<SOAP-ENV:Envelope>
SOAP Envelope
SOAP Header
header是可扩展设计的一部分,允许符合soap标准的信息扩展,header是envelope的子元素,每一个header元素有它自己的子节点。Exception Handling
异常处理,在这种情况下soap处理器不能够解析一段信息,一个soap错误就产生了。定义在 Fault 元素中,它的子元素是faultcode,定义了发生错误的种类,SOAP 1.1 defines four values for the faultcode element:
Adding SOAP Support


Web Services Definition Language (WSDL) WSDL-wiki
WSDL Syntax
Invoking Existing Web Services: A Sample
To invoke a Web Service, we can either write a SOAP client or use an existing generic one. Thewww.soapclient.com site provides a Web interface that allows us to enter the WSDL file and invoke the service. Before we can launch the service, we need to find the WSDL file. In this case, we can find some sample WSDL files at www.xmethods.net, a public repository of Web Services. For our example, we will invoke a Web Service that can print the traffic conditions of a specified California highway. Use the following instructions:
-
Visit the www.soapclient.com/soaptest.html site.
-
Type www.xmethods.net/sd/2001/CATrafficService.wsdl in the WSDL address field.
-
Select HTML instead of XML for the output.
-
Click Retrieve, which loads the WSDL file from across the Internet.
-
In the textfield, type 101 (for Highway 101) and click Invoke to invoke the service.
-
The resulting screen should print text that explains the current conditions for Highway 101.
This example illustrates how straightforward it is to invoke a Web Service from a browser. The user, in most cases, will not even be aware that Web Services are being used to return the values. Of course, the user can just as easily be a program, in which case the program would programmatically pass the appropriate parameters.
以上例子可以使用
以上是运动员的soap形式。