How XML is used. Why do you need XML? The xml language is used for


XML is used in many aspects of web development, but its main purpose is to make it easier to store and transfer data.

XML separates data from HTML

If you need to display dynamic data in an HTML document, it will take too long if, whenever this data has changed, you edit the HTML document itself.

WITH XML data can be stored in separate XML files. In doing so, you focus on using HTML / CSS for display and templating, and you can be sure that the incoming new data does not require any changes in the HTML code of the document.

XML simplifies data distribution

In the real world, computer systems and databases use data in incompatible formats.

XML data is stored in plain text format. This provides software and hardware independence.

This makes it easy to create data that can be used by a wide variety of applications.

XML makes data transfer easy

One of the most time-consuming problems of developers has always been and still remains the problem of data exchange between incompatible systems.

Passing data in XML significantly reduces the complexity of this problem, since data in this format can be read by different incompatible applications.

XML makes it easy to modify the platform

Moving to new systems (hardware or software platforms) always takes a long time. A lot of data needs to be converted to new formats. In this case, often incompatible data is lost.

XML data is stored in text format. This makes it much easier to expand or upgrade operating systems, migrate to new applications or browsers without the risk of losing data.

XML makes your data more accessible

Your data can be accessed not only by HTML documents, but also by any other application.

XML makes your data available to all kinds of "reading machines" (voice machines, news feeds, etc.), making it much easier for people with visual impairments and other physical problems to access it.

XML is used to create new Internet languages

Many programming languages ​​on the Internet have been created using XML.

Here are some examples:

  • XHTML
  • WSDL for describing available web services
  • WAP and WML as markup languages ​​for handheld devices such as PDAs
  • RSS languages ​​for news feeds
  • RDF and OWL for resource description and ontology
  • SMIL for describing multimedia for the web

Let's consider the technology of using XML to transfer data to the server.

We have already considered 2 ways of transferring data to the server: it is a simple text with a delimiter and JSON. But they have disadvantages:

  • Lack of data types. JSON only has string, number, null, boolean. Those. limited data set.
  • It is difficult to control the integrity of the transmitted data.
  • Difficult to visualize data i.e. complex objects are difficult to display, for example, in the form of html code.
  • Difficult to transform data, i.e. it is difficult to convert properties of one object to properties of another object.

Now let's turn to XML as a way of transferring data. XML(eXtensible Markup Language) is a markup language for describing, storing and transmitting structured data. XML is used everywhere today.

There are many technologies based on XML: DOM (programmatic interaction with data), XLink (pointers and links), XPath (description and selection of elements), XSL, XSLT (transformation of an XML document).

Parsing the XML package looks like this:

// XMLHttpRequest object var req = getXmlHttpRequest (); // Install the handler req. onreadystatechange = function () (if (req. readyState == 4) ( // state "4 - comlete" var xml = req. responseXML; ))

You don't even need to do serialization and deserialization here. This is done by the object itself. As soon as the server sends XML data, it is already in parsed form (responseXML - DOM document model). Read more about DOM technology in previous articles on the site.

Sometimes, for debugging, you need to serialize and deserialize XML data (to transfer data to the server, this is done automatically, you do not need to do it manually). Let's serialize to a string:

// for IE var str = dom. xml // for Firefox var serializer = new XMLSerializer (); var str = serializer. serializeToString (dom);

For IE, the working code is shorter because it already has an object for serialization built into it, and in other browsers only an XMLSerializer object appears for serialization.

When working with XML data, we usually deal with the DOM document model. Therefore, it is worth remembering some points of the DOM (read about this in previous articles). Let me just remind you of the ways to access the DOM element of the model:

// root element var root = xmlDOM. documentElement; // the first item in the collection var book = root. childNodes [0]; // child element var title = book. childNodes [0]; // element text node alert (title. firstChild. nodeValue);

You can also select elements of the same type from the DOM of the document model. Attention! GetElemensById functions - no, because in XML, id can mean anything, not just an identifier, so it is not used.

// fetch all elements with one tag var books = xmlDOM. getElementsByTagName ("book");

XML is also actively used not only for data presentation, but also for data exchange in a server-oriented architecture. This is an approach in which we represent a complex application not as a classic client-server application, but as a set of services (services), each of which is responsible for its own tasks. And each service has entry points (interaction points). There is no clear client here, because one service can be a client of another service. It turns out such a distributed technology. There are several approaches to building such technologies - remote procedure call, SOAP.

In order for the services of different clients to interact, they must speak the same language (it does not matter what operating system the service has). And such a language was developed and named RPC.

XML-RPC protocol

RPC(Remote Procedure Call) - remote procedure call. It is a communication protocol between two remote points. It allows point "a" to call a function on the remote point "b".

There are several implementations of the RPC protocol. Let's take a look at an XML-based implementation.

Basically, the client and server just exchange some XML fragments.

XML-RPC provides the following data types:

  • boolean.
  • integer.
  • double.
  • string.
  • date / time.
  • base64.
  • array.
  • struct.
  • null.

Those. when transferring a certain data type, you need to declare what kind of data type it is. The structure is similar to a JSON object.

Transforming XML data

XSLT is used to transform data received from the server in the form of XML.

XSLT(eXtendable Stylesheet Language Transformation) is a technology that helps to receive XML as input, and form anything at the output.

Converting XSLT to javaScript - IE

var dom = new ActiveXObject ("MSXML2.DOMDocument"); dom. async = false; dom var xsl = new ActiveXObject (" [email protected]"); xsl. async = false; xsl. load (" my.xsl "); // transformation itself var result = dom. transformNode (xsl);

Converting XSLT to javaScript for Firefox. Ghrome, Opera

var xslStylesheet; var xsltProcessor var myXMLHTTPRequest = mew XMLHttpRequest (); myXMLHTTPRequest. open ("GET", "example.xsl", false); myXMLHTTPRequest. send (null); // get xml xslStileshett = myXMLHTTPRequest. responseXML; xsltProcessor myXMLHTTPRequest = new XMLHttpRequest (); myXMLHTTPRequest. open ("GET", "example.xml", false); myXMLHTTPRequest. send (null); // transformation itself var xmlSource = myXMLHTTPRequest. responseXML; var resultDocument = xsltProcessor. transformToDocument (xmlSource);

XML has already attracted a lot of attention from developers and Internet users. Today, the number of adherents of this new technology is growing as rapidly as the number of reports about the next obstacles it has taken on the path to universal acceptance. Despite the fact that XML is very young (the international organization W3C approved the specification "Extensible Markup Language (XML) 1.0" a little less than a year ago - at the beginning of February 1998) and some components of this language are still under development, new languages ​​are already appearing today Based on XML, numerous Web servers are emerging that use this technology to organize the information stored on them. The Internet world around us is once again transforming, and we can become participants in this process today.

The purpose of this article is an attempt to show some of the capabilities of XML using specific examples, to answer a number of questions that often arise when meeting a new language. What is XML? What are its advantages over our familiar HTML language? Can You Use XML on Your Web Pages Today? And if so, how?

At the end of the article, there are links to other Internet resources, with the help of which you can also obtain more complete information on specific issues of interest to you related to the use of XML and not touched upon by us in this article. Full specifications of XML and related languages ​​are available on the official W3C page -

What is the new markup language for?

Much simpler and more convenient than SGML, the HTML language allows you to define the design of document elements and has a certain limited set of instructions - tags, with the help of which the markup process is carried out. HTML instructions are primarily intended to control the process of displaying the contents of a document on the screen of a client program and thereby determine how the document is presented, but not its structure. As an element of the hypertext database described by HTML, a text file is used that can be easily transmitted over the network using the HTTP protocol. This feature, as well as the fact that HTML is an open standard and a huge number of users have the opportunity to use the capabilities of this language for formatting their documents, undoubtedly influenced the growth in popularity of HTML and made it today the main mechanism for presenting information on the Web.

However, modern applications need not only a language for presenting data on the client's screen, but also a mechanism that allows you to define the structure of a document, describe the elements it contains. HTML has a simple set of commands and quite successfully copes with the task of describing textual information and displaying it on the screen of a browser-viewer. However, the displayed data itself has nothing to do with the tags that are used for formatting, so parsers do not have the ability to use HTML tags to find the parts of the document we need. Those. having met, for example, such a description

rose,

the viewer will know what color to display the text contained within the tags and, probably, will display it correctly, but it is absolutely indifferent to where this tag is found in the document, what other tags the current fragment is enclosed in, whether there are fragments nested in it, whether the relationships between objects are built correctly. This "indifference" to the structure of the document leads to the fact that the search or analysis of information within it will not differ in any way from working with a solid text file that is not divided into elements. And this, as you know, is not the most effective way to work with information.

Another significant disadvantage of HTML is the limited set of its tags. DTD rules for HTML define a fixed set of descriptors and therefore it is not possible for the developer to enter his own special tags. Although new extensions of the language appear from time to time (today the latest version of HTML is HTML 4.0), the long path of their standardization, accompanied by constant disagreements between the main browser manufacturers, make it almost impossible to quickly adapt the language, its use for displaying specialized information (for example, multimedia , mathematical, chemical formulas, etc.).

Summing up all that has been said, it can be argued that HTML today does not fully meet the requirements of modern developers for languages ​​of this kind. And it was replaced by a new hypertext markup language, a powerful, flexible, and, at the same time, convenient XML language. What is its dignity?

XML ( Extensible Markup Language) is a markup language that describes a whole class of data objects called XML documents. This language is used as a means for describing the grammar of other languages ​​and for checking the correctness of documents. Those. XML itself does not contain any tags for markup, it simply defines the order in which they are created. Thus, if, for example, we consider that to denote an element rose you must use the tag in the document ;, then XML allows us to freely use the tag we define and we can include in the document fragments like the following:

rose

The set of tags can be easily expanded. If, suppose, we also want to indicate that the description of a flower should go within the meaning of the description of the greenhouse in which it blooms, then we simply set new tags and choose their order:

rose

If we want to plant a few more flowers there, then we must make the following changes:

rose tulip cactus

As you can see, the process of creating an XML document itself is very simple and requires from us only basic knowledge of HTML and an understanding of the tasks that we want to perform using XML as a markup language. This gives developers a unique opportunity to define their own commands that enable them to most effectively define the data contained in the document. The author of the document creates its structure, builds the necessary connections between the elements, using those commands that satisfy his requirements and achieves the type of markup that he needs to perform operations of viewing, searching, analyzing the document.

Another of the obvious advantages of XML is the ability to use it as a universal query language for information stores. Today, deep in the W3C, a working draft of the XML-QL (or XQL) standard is under consideration, which may seriously compete with SQL in the future. In addition, XML documents can act as a unique way of storing data that includes both means for parsing information and presenting it on the client side. One of the promising areas in this area is the integration of Java and XML technologies, which allows using the power of both technologies to build machine-independent applications that also use a universal data format for information exchange.

XML also allows you to control the correctness of data stored in documents, check hierarchical relationships within a document and establish a single standard for the structure of documents, the content of which can be a variety of data. This means that it can be used in the construction of complex information systems, in which it is very important to exchange information between different applications operating in the same system. By creating the structure of the information exchange mechanism at the very beginning of the project, the manager can save himself in the future from many problems associated with the incompatibility of the data formats used by various components of the system.

Also, one of the advantages of XML is that programs for processing XML documents are not complicated, and today all kinds of software products designed to work with XML documents have appeared and are freely distributed. XML is supported today in Microsoft Internet Explorer 4/0 and in beta versions of IE5. Its support was announced in subsequent versions of Netscape Communicator, Oracle DBMS, DB-2, and MS-Office applications. All this suggests that, most likely, in the near future, XML will become the main language of information exchange for information systems, thereby replacing HTML. Well-known specialized markup languages ​​such as SMIL, CDF, MathML, XSL have already been created on the basis of XML, and the list of working projects of new languages ​​under consideration by the W3C is constantly growing.

What does an XML document look like?

First Second subparagraph 1 Third Last

Rules for creating an XML document

RussiaNovosibirsk</country>

Language constructs

Data items

rose Novosibirsk rose Novosibirsk Siberia Novosibirsk State Technical University
very good institute Novosibirsk State University
not bad either

I think that you already imagine why you need Html(Yes, Html). It is needed to present data in the browser. That is, there is Html code and corresponding to this HTML code a certain kind. However, modern trends require not only the display of data, but also their competent internal structure.

That's it for create a structure and there is an XML language... Simple example:

Green apple

For us people, everything becomes immediately clear. An image immediately appears in my head " green apple"however, how to explain to the computer that this is an apple, not an orange, a man or our galaxy? Here again comes to the rescue XML, where we can create any tags, making it clear where is the apple, where is the orange, where is the person, and where is our galaxy. I hope I explained it clearly.

Now about the most important thing. The main feature of XML is its versatility.... That is XML understands any modern language. And since XML is a text file, then you can work with it in a regular notebook. Now specifically to practice, where is XML used:

  • Settings file... Settings in XML file very easy to read and write. For this reason, there are hundreds of XML files.
  • Communication bridge between programs written in different languages. A very important feature resulting from the versatility of the language, and it is regularly used in complex systems.
  • Data storage... In fact, this is a kind of analogue of a database, but does not require DBMS(For example, MySQL). And thanks to the query language XPath it becomes possible to communicate easily with this " database".

And, finally, from my own practice I can give you the simplest example. I have an XML sitemap on my site. There are links to all pages of the site. This is a very convenient and important thing for good site indexing, however, it is inconvenient to manually add a new page there every time. Therefore, thanks to knowledge of working with XML, I easily automated this business. So that XML is a useful language, which any programmer should know at least in general terms.

The Extensible Markup Language (XML) was developed by the World Wide Web Consortium (W3C) XML Working Group. Here's how the creators describe it:

“The Extensible Markup Language (XML) is an integral part of the SGML language ... It is designed to facilitate the use of SGML on the Web and to accomplish the tasks currently performed using HTML. XML is designed to improve the use and interoperability of SGML and HTML. "

This is an excerpt from the XML 1.0 specification, created by the XML Working Group in February 1998. The entire document can be found on the W3C site at http://www.w3.org/TR/REC/-xml.

XML is a markup language designed specifically for posting information on the World Wide Web, similar to the Hypertext Markup Language (HTML), which originally became the standard language for creating Web pages. Since HTML fully satisfies all of our needs, the question arises: Why did you need a completely new language for the Web? What are its advantages and advantages? How does it interact with HTML? Will it replace HTML, or just improve it? Finally, what is SGML, of which XML is a part, and why can't you use SGML proper for your Web pages? In this chapter, I will try to answer all of these questions.

XML purpose

HTML provides a fixed set of elements that you can use to place components on a typical Web page. Examples of such elements are headings, paragraphs, lists, tables, images, and links. For example, HTML is great for

creating a personal home page. Below is the description of the home page in HTML codes:

Home Page

Michael Young "s Home Page

Welcome to my Web site!

Web Site Contents

Please choose one of the following topics:

  • Writing
  • Family
  • Photo Gallery

Other Interesting Web Sites

Click one of the following to explore another Web site:

  • "one. XML should become a language for direct use on the Internet. "

    As you can imagine, XML was designed primarily for storing and distributing information on the Web.

    "2. XML will support a wide variety of applications. "

    Although its main purpose is to distribute information on the Web through servers and browsers, XML is also designed to be used by other programs. For example, XML is used to exchange information between financial programs, to distribute and update software products, and to write voice scripts when delivering information over the phone.

    "3.XML will be SGML compliant."

    XML is a specialized branch of SGML. The advantage here is that SGML software can be easily adapted to work with HTML.

    "4. It will be easier to write programs that process XML documents. "

    Practical use of XML requires that it be easy to write browsers and other programs that process XML documents. In fact, the main reason for separating XML from SGML was the availability of writing programs to process XML documents.

    "5. The number of additional features in XML should be kept to a minimum, ideally zero. "

    The minimum number of additional functions in XML makes it easy to write programs to process XML documents. The abundance of additional pluggable features in SGML has become a major reason why it is practically unsuitable for presenting Web documents. Additional SGML features require tag delimiter characters to be overridden (usually ) and skip the end tag to allow the processor to detect the end of the element. When strictly writing an SGML document processing program, you must consider the possibility of all additional functions, even if they are rare.

    "6. XML documents should be understandable and clear to the user. "

    XML aims to become the lingua franca (universal language) for the exchange of information among users and programs around the world. According to this concept, users, as well as specialized programs, should be able to create and read XML documents. Accessibility and transparency for the user sets XML apart from most other formats used in building databases and text documents.

    The XML document can be easily read by the user because it is described in plain text and has a logical hierarchical structure in the form of a tree. You can simplify XML documents by assigning meaningful names to elements, attributes, and objects, and adding helpful comments. (This is discussed later in this chapter.)

    "7. XML development should be completed quickly enough. "

    XML will become an accepted standard only if programmers and users accept it. This standard should be created before society accepts alternative standards that are increasingly being created by software companies.

    "eight. XML should be formal and concise. "

    The XML specification is written in a formal language used to represent computer languages, with a notation known as the Extended Backus-Naur Form (EBNF). This formal language, although difficult to understand, is devoid of ambiguity and greatly facilitates the writing of XML documents, and especially the programs for processing them.

    "9. XML documents will be easier to create. "

    Practical use of XML as a markup language for Web documents simplifies not only the writing of processing programs, but also the process of creating the XML documents themselves.

    "10. The compressed form is not important in XML markup. "

    In accordance with clause 6 (the XML document must be clear and understandable for the user), the XML markup should not be overly condensed in order not to conflict with the stated purpose.

    Standard XML Applications

    You can use XML for more than just describing an individual document. An individual user, company, or standards committee can define the required set of XML elements and document structure to apply to a particular class of documents. Such a set of elements and a description of the structure of a document is called an XML application or XML vocabulary.

    For example, an organization can define an XML application for creating documents that describe molecular structures, human resources, multimedia presentations, or contain vector graphics. At the end of the chapter, there is a list of some common XML applications that have already been created and are planned to be created.

    An XML application is typically defined by creating a Document Type Descriptor (DTD), which is a valid XML document component. A DTD is structured around a database schema: it sets and defines the names of elements that can be used in a document, the order in which elements can appear, the attributes of elements that can be applied, and other features of the document. For practical use of an XML application, you usually include its DTD in your XML document; the presence of a DTD in a document limits the elements and structures that you will use, so your document meets the standards of this application. The XML document descriptions discussed earlier in this chapter did not include DTDs. You will learn how to define and use DTDs in Chapter 5.

    The advantages of using standard XML applications to design your documents are that you can share documents with all other users of the application, and the document can be processed and displayed using the software that is already built for the application.

    XML applications that enhance the quality of XML documents

    In addition to XML applications for describing specific classes of documents, there are several XML applications that you can use within any type of XML document. These applications make it easier to create a document and improve its quality. Below are examples of such applications.

    • Extensible Stylesheet Language (XSL) allows you to create powerful style sheets using XML syntax.
    • XML Schema allows you to design detailed schemas for your XML documents using standard XML syntax, which is a more powerful alternative to using DTDs.
    • XML Linking Language (XLink) gives you the ability to link your XML documents. It supports multiple targeted links and other useful features, providing more freedom than HTML link organizing mechanism.
    • XML Pointer Language (XPointer) allows you to define flexible target links. When you use XPointer and XLink together, you can organize links to anywhere in the target document — not just jump to highlighted items.

    XLS is covered in Chapter 10. Other XML applications are not yet ready to go and are not covered in this book. (XLink and XPointer are not supported in Internet Explorer 5).

    As you can see, XML is not only a useful tool for describing documents, but also serves as a basis for building applications and extensions that may be needed as the Internet develops.

    Real use of XML

    While the concept of XML is quite interesting, you might wonder how to put it into practice. This section provides a list of examples of such uses of XML, both widely used and promising. If there are relevant XML applications for practical use, they will be shown in parentheses. For example, you might find out that the MathML XML application will allow you to format mathematical formulas.

    Link... For a more complete list of current and emerging XML applications, including their detailed descriptions, see the Oasis SGML / XML Web page (http: //www.oasis-open.arg/cover/ocml.htmW applications).

    • Working with databases. Like traditional databases, XML can be used to assign a label to each field of information within each database record. (For example, you can tag each name, address, and phone number inside address list entries.) You can then display the data in a variety of ways and organize searches, sorting, filtering, and other processing of the data.
    • Structuring documents. The hierarchical structure of XML documents is ideal for marking up the structure of documents such as novels, scientific papers, and plays. For example, you can use XML to mark up a play with acts, scenes, characters, storylines, scenery, and so on. XML markup enables programs to display or print a document in the required format; find, extract or manipulate information in a document; generate tables of contents, summaries and annotations; process information in other ways.
    • Working with vector graphics (VML - Vector Markup Language).
    • Multimedia presentations (SMIL - Synchronized Multimedia Integration Language, HTML + TIME - HTML Timed Interactive Multimedia Extensions).
    • Description of channels. Channels are Web pages that are automatically sent to subscribers. (CDF - Channel Definition Format).
    • Description of software packages and their relationships. Such descriptions provide distribution and updating of software products on the network (OSD - Open Software Description).
    • Interaction of applications over the Web using XML co-communications. These messages are independent of operating systems, object models, and computer languages ​​(SOAP - Simple Object Access Protocol).
    • Sending electronic business cards via e-mail.
    • Financial information exchange. The exchange of information in an open and understandable format is carried out between financial programs (such as Quicken and Microsoft Money) and financial institutions (banks, public funds) (OFX - Open Financial Exchange).
    • Creation, management and use of complex digital forms for commercial Internet transactions. Such forms may include digitized signatures that make them legally recognized (XFDL - Extensible Forms Description Language).
    • Exchange of requests for employment and resumes (HRMML - Human Resource Management Markup Language).
    • Formatting mathematical formulas and scientific information in
    • Web (MathML - Mathematical Markup Language).
    • Description of molecular structures (CML - Chemical Markup Language).
    • Coding and display of information about DNA, RNA and strands (BSML - Bioinformatic Sequence Markup Language).
    • Genealogical Data Markup Language (GeDML).
    • Astronomical Markup Language (AML) exchange.
    • Creation of musical scores (MusicML -Music Markup Language).
    • Working with voice scripts to deliver information over the phone. Voice scripts can be used, for example, to generate voice messages, product availability inquiries, and weather forecasts (VoxML).
    • Processing and delivery of information by courier services. Federal Express, for example, already uses XML for this purpose.
    • Presentation of advertising in the press in digital format (AdMarkup).
    • Legal filing and electronic exchange of legal information (XCL - XML ​​Court Interface).
    • Weather Observation Markup Format (OMF) coding.
    • Exchange of information on transactions with real estate (RETS - Real Estate Transaction Standard).
    • Exchange of insurance information.
    • Exchange of news and information using open Web-standards (XMLNews).
    • Presentation of religious information and markup of texts of worship (ThML - Theological Markup Language, LitML - Liturgical Markup Language).






2021 gtavrl.ru.