[WS] Web Service series (iii) XML Technology

Source: Internet
Author: User
Tags xml example

We are no longer familiar with the XML name. It can be said to be simple and complex, because XML itself has simple and clear rules, but with the emergence of more and more new XML-based applications, it has evolved into a variety of complex languages. I hope this post will solve the following problems for you: what is XML, why we need it, and how to use it.

XML is the extensible markup language. It is a markup language. Markup language features three elements: Tag, element, and attribute. Let's take a look at a simple XML example, as shown below:

<? XML version = "1.0" ?>
< Team >
< Member Leader = "True" >
< Name > Zhang Hao </ Name >
< Age > 25 </ Age >
</ Member >
< Member Leader = "False" >
< Name > Sun Liang </ Name >
< Age > 25 </ Age >
</ Member >
</ Team >

It can be seen that the XML document has a tree structure. It should be said that this structure is very suitable for describing data, so many people will use XML as the method of persistent data. In the XML document above, which is enclosed by Angle brackets?MarkSuch as <team> and <member>.End mark,Start markIf it is an empty tag, you can write in the form of <team/>. The start tag and end tag are collectively referred to as the content between them.Element;AttributeIs a name-value pair. For example, leader = "true" indicates that leader is the attribute of the member element.

From the XML format, it is easy to think of HTML. html is also a markup language, and WML, XHTML, and so on are all Markup languages. xml differs from them in the following aspects: XML is the meta language used to create these Markup languages. If we use object-oriented languages for analogy, HTML, WML, XHTML, and so on all inherit XML, which is a subclass of XML. Therefore, all XML features are also available. For example, a document can only have one root element. tags can be nested but cannot be crossed. Attributes must be enclosed in double quotation marks, and start and end tags must be matched. If an XML document does not comply with these rules, it is invalid. In addition, you can add additional constraints to the XML format through DTD or schema. For example, you can require at least one <member> element under the <team> element, <age> the element is optional. If the XML document is valid and meets these additional requirements, the document is in good format.

DTDAndSchemaIs two ways to verify whether the XML format is good. DTD appears early. It is not in XML format; schema is in XML format and has better functions and supports regular expressions. These files can be referenced in the XML document header. when processing the XML document, it will be verified. If the verification fails, no further processing will be performed. To save space, the format of DTD and schema is not detailed here. GenerallyProgramYou need to define your own XML format, it is best to first define DTD or schema, we usually use most of the XML documents such as Web. XML, struts-config.xml have their own DTD or schema to ensure the format.

Let's talk about the namespace issue. The namespace is the tag prefix. XML documents may be merged in actual applications. This prefix ensures that the merged documents do not contain conflicting tags. To ensure this uniqueness, The namespace generally uses the URL format, for example:

< Myns: Team Xmlns: myns = "Http://www.mysite.com" >

</ Myns: Team >

Here, myns is a casual name. The xmlns: myns attribute next to it specifies the namespace represented by this name. It should be noted that the team name really makes sense. A complete tag should beNamespace: Tag NameIn this way, XML documents with namespaces can be read in disorder, so you need to identify which are important and which can be ignored temporarily.

As a way to describe data, as long as you use your imagination, XML can be used for an unlimited number of purposes. Have you subscribed to RSS? That is also one of them. In web services, we use XML to transmit request and response data between service providers and users (soap is one of the formats), and use XML to describe services (such as WSDL ), the Service Group is also packaged into a complete process (for example, BPEL4WS) using XML. These format specifications will be described in the following post. By the way, XML's scalability makes them.

To use XML in a program, you may want to read information from the configuration file in XML format, or provide data in XML format to other systems, or use other methods, the most direct method is to use the XML interpreter. Currently, Dom, sax, JDOM, and JAXP are common. JAXP is a unified interface as Java extension, the first three are their implementation methods. There are many comparisons between these interpreters.ArticleFor reference, I will not go into details here. I have used DOM and JDOM and prefer the latter becauseCodeThe amount is smaller.

Although it is also a web service to directly use the XML interpreter to process XML format information and transfer it between the service provider and the user, it is too troublesome, we will have to deal with various trivial issues (such as data type ing) and generate a large amount of code. Therefore, it is necessary to use an interpreter that specifically processes various specialized XML formats in Web Services. Apache axis (formerly Apache SOAP) is one of them, which can interpret soap information, it is much easier than simply using the XML interpreter mentioned above.

There is too much content about XML. For example, XSL is used to represent XML, XSLT is used to convert between different formats of XML, XPath is used to find appropriate elements in XML documents, and so on. How do I solve the problem mentioned at the beginning of the post? It doesn't matter if you don't know it. There is an XML area on the IBM developer website, where you will surely be very eye-catching. If you are a newbie, let's take a look at this tutorial first, which is much better than I did, haha... the next post begins with soap.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.