Xml is used for transfer. XML Language - Introduction


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

We have already looked at 2 ways to transfer data to the server: plain 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 transmitted data.
  • Difficult to visualize data, e.g. complex objects are difficult to display, for example, in the form of html code.
  • Difficult to transform data, i.e. It is difficult to transform the properties of one object into the properties of another object.

Now let's turn to XML as a method of data transfer. XML(eXtensible Markup Language) is a markup language designed to describe, store and transmit structured data. Today XML is used everywhere.

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

Parsing the XML package looks like this:

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

Here you don’t even need to do serialization and deserialization. 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 into 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 a built-in object for serialization, while in other browsers the XMLSerializer object for serialization only appears.

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

//root element var root = xmlDOM. documentElement; //first element 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! There are no getElemensById functions, because in XML id can mean anything, not just an identifier, so it is not used.

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

XML is also actively used not only for data representation, but also for data exchange in server-oriented architecture. This is an approach in which we present a complex application not as a classic client-server application, but as a set of 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. This turns out to be a distributed technology. There are several approaches to building such technologies - remote procedure call, SOAP.

In order for services from 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 called RPC.

XML-RPC protocol

RPC(Remote Procedure Call) - remote procedure call. This is a protocol for interaction between two remote points. It allows point “a” to call a function on remote point “b”.

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

Essentially, the client and server simply exchange some XML fragments.

XML-RPC provides the following data types:

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

Those. When passing a certain data type, you must declare what the data type is. The structure is similar to a JSON object.

Converting XML Data

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

XSLT(eXtendable Stylesheet Language Transformation) is a technology that helps you receive XML as input and form whatever you want as 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" ); //the transformation itself var result = dom. transformNode(xsl);

Convert 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); //the transformation itself var xmlSource = myXMLHTTPRequest. responseXML; var resultDocument = xsltProcessor. transformToDocument(xmlSource);

Quite often, many users of modern computer systems and software products of various types encounter files with the .xml extension. Many people simply have no idea what kind of document this is or how to open it. Now it will be considered. At the same time, we will find out what it is and what it is needed for.

What is an XML file

Let's start, perhaps, with the fact that, from the point of view of modern computer technologies and programs used to create documents of this type, it is a text file in which the commands of the universal extensible markup language are written, which is quite reminiscent of the well-known markup tool HTML.

Typically, an XML file contains general information about an object, which is expressed descriptively (more on this later). As for the data stored in such containers, it can be databases often used for video and audio catalogs on the Internet, saved user preferences for programs and applications, as well as entire web pages.

As an example, you can take, say, an audio album of some artist. The XML file includes information about the year of release, genre, number and names of tracks, popularity, etc. However, when visiting resources on the World Wide Web, the surfer does not need to think about physically opening such an information file, since even when playing a song online in a player All data will be displayed similar to those contained in standard MP3 files in the form of ID3 tags. The information is loaded onto the track being played.

XML file type

If you look at the file, you will immediately notice that in it the properties of any object are described using tags and attributes that are set manually.

We are not talking about the basic commands of the language itself, since the average user does not need such information. The only thing that can be noted is that there is no specific number of elements used to describe an object in this format: how many are needed is specified.

How to open standard XML format

Now let's see how to open an XML file. As many have probably already understood, this is a text file, which means that the easiest way to view or edit it is to use any editor, even the most primitive one. Yes, at least the same “Notepad” from the standard Windows set.

However, everything is not so simple here. The fact is that double-clicking a file without setting the appropriate association with any program will not open. At best, the system will offer a list of the most suitable applications. You can select a program of your choice, and at the same time check the box next to the option to constantly use the selected application for all files of this type.

You can do it differently by right-clicking on the file and then selecting the “Open with...” command, after which, again, select the desired application either from the list, or specify the location of the main executable component (most often this is an EXE file).

The third way to open an XML file is to initially launch the program and then use the file open menu (in most cases this is Ctrl + O). In this case, it is absolutely not necessary to use Notepad. Please, the file opens without any problems in the same Word application and similar ones. Even Microsoft Excel is capable of opening data in this format.

However, if there is a need to edit the XML format, then it is better to use professional utilities that support language syntax, for example, Oxygen XML Editor, XML Marker or EditiX Lite Version. Naturally, these are not all utilities that can work with the file language at the highest level. Today you can find a lot of such programs.

Now a few words about why sometimes an XML file error appears when opening. Most often this is due to a violation of the integrity of the file itself, as well as incorrect introduction of descriptive attributes or tags. Additionally, Excel has a limit on how many rows can be displayed, so in this case the data may not be complete when opened.

Possible errors when opening an XML file as an email attachment

Sometimes errors may appear when you try to open a file that is an email attachment. Most often this applies to standard email clients like Outlook Express.

The fact is that the attachment is first saved as temporary data (very often with an additional .tmp added to the main extension), and it is this that is accessed.

To avoid this situation, you simply need to initially save the attachment in its original format to any convenient location on disk or removable media, and then use the standard methods described above.

Instead of a total

As you can see, there is nothing difficult in understanding the structure and methods of opening files of this format. Here, however, the issue of creating XML data was not fundamentally considered, since to fully understand the process you need to know at least the basics of the language itself. Otherwise, I think that users will not have any difficulties with files of this format.

In the Windows operating system, most programs store their settings in the registry. However, special files are also often used to store application settings, usually located directly in the directories with executable files or in subfolders. Configuration files can have different formats, including the XML format, which is the subject of this short article.

What is this XML format, what is it for and where is it used

In truth, the goals for which the XML format was created (it appeared in 1996) were, so to speak, global. XML, or eXtensible Markup Language, was developed as a means of providing interoperability for the transfer of structured data between different software systems, especially those used on the Internet. This language is so universal that XML files are understood even by incompatible applications of different operating systems, which, of course, greatly simplifies the task of programmers to exchange information between software platforms.

In addition, XML is actively used in website design. It is sometimes promoted as a more advanced and versatile analogue of the hypertext markup language HTML, but these languages ​​actually serve different purposes. HTML is primarily responsible for displaying data, while XML was designed to convey and store that data. XML is also used to create new Internet languages. By the way, RSS, familiar to many, used in distribution through news channels, is based precisely on XML.

Programs for opening and viewing files in XML format

We figured out what kind of XML format this is, now let's see how to work with it. In truth, developers and system administrators usually face the need to edit XML files, but let's still assume that you have the same need. How to open an XML file? In general, you can view it with any text editor, even Notepad, but it is much more convenient to use special programs for these purposes.

Notepad++

If you're looking for something to open XML with, try Notepad++– a universal text editor designed for creating and editing code. Lightweight, fast and simple, it's ideal for working with all kinds of configuration files. The editor supports syntax highlighting, changing encoding, there is a powerful built-in search for various parameters, in a word, everything that a programmer and not only him needs.

XMLPad

Unlike Notepad++, XMLPad is a highly specialized editor. This is exactly what you can and should use to open the XML format, since it was created specifically for working with files of this type. In addition to viewing and editing XML documents, the XMLPad editor supports document validation and inspection, conversion to DTDs, importing data from HTML, and much more. As expected, the application has syntax support and a search and replace tool. One of the features of the program is the presence of a built-in mini-browser for opening URL links.

For those who are more serious about learning web languages, we can offer an advanced and at the same time simple and convenient XML editor on the Java platform. The program supports the creation and editing of XML, XSL, XSD and DTD files, it also has a built-in converter to scripts, an XSLT and XQuery debugger, tools for working with visual XML diagrams and many other components. Disadvantages - the program is paid, and it does not support the Russian language.

XML Marker

A good way to open an XML file is to use a simple editor XML Marker. It is not as sophisticated as Oxygen XML Editor, but it copes well with most of the tasks that a user faces when working with XML files. There is a representation of the tree structure of the document with the ability to quickly navigate to selected lines by tags, convenient navigation, and a full set of tools for working with text data. The disadvantage of the program is that there is no Russian language.

Browsers

There is another simple way to read an XML file, however, we are talking here only about reading. Open a new tab in Google Chrome or any other browser and drag the XML file onto the browser window. The document will be presented in a structured form, with syntax highlighting, everything as it should be.

View XML files online

You can work with XML documents not only using desktop programs; it is also easy to open XML online. Here are two simple online editors for you to consider.

XmlGrid

A simple-looking but quite functional online XML file editor, available at xmlgrid.net. The service supports the creation, modification, validation and conversion of XML documents, and additionally has the function of designing site maps. The code of the edited file can be pasted into a web form from the clipboard, via a URL, or by uploading the document itself to the server. The contents of the file are displayed as a data table, in which each field is a separate cell.

XML EDITOR

You can also open an XML file online using the online XML EDITOR, which is part of the TutorialsPoint application suite, one of the largest learning resources. To use the service, go to www.tutorialspoint.com, click the “Tools” link at the top of the page, find XML EDITOR in the list of web applications and open it. You will see a simple text editor window with two columns. The left one is where code is written and edited, the right one displays the tree structure of the document. You can upload a file to the editor either from your computer or from any website by specifying the URL.

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

“Extensible Markup Language (XML) is a component of SGML... It is designed to make SGML easier to use on the Web and perform tasks that are currently accomplished using HTML. XML is designed to improve the use and interoperability of SGML and HTML."

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

XML is a markup language designed specifically for placing information on the World Wide Web, similar to the hypertext markup language HTML (Hypertext Markup Language), which initially became the standard language for creating Web pages. Since HTML completely satisfies all our needs, the question arises: why was a completely new language needed for the Web? What are its advantages and advantages? How does it interact with HTML? Will it replace HTML, or just improve upon it? Finally, what is SGML, of which XML is a part, and why can't SGML itself be used for Web pages? In this chapter I will try to answer all these questions.

Purpose of XML

The HTML language provides a fixed set of elements that you can use to place components on a typical Web page. Examples of such elements include 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:

  • "1. XML should become the language of direct use on the Internet."

    As you might have guessed, XML was designed primarily for storing and distributing information on the Web.

    "2. XML will support a large number of applications."

    Although its primary purpose is to distribute information on the Web through servers and browser programs, 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 compatible with SGML."

    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."

    For practical use of XML, it is necessary that it be fairly easy to write browsers and other programs that process XML documents. In fact, the main reason for separating XML from SGML was the ease of writing programs to process XML documents.

    "5. The number of additional functions in XML should be minimal, and ideally zero.”

    The minimal number of additional functions in XML makes it easy to write programs to process XML documents. The abundance of additional plug-in functions in SGML was the main reason that determined its practical unsuitability for representing Web documents. Additional SGML features require overriding delimiter characters for tags (usually ) and skipping the end tag so that the processor detects the end of the element. When strictly writing an SGML document processing program, it is necessary to take into account the possibility of all additional functions, even if they are rare.

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

    XML is intended to become the lingua franca (universal language) for exchanging 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 distinguish XML from most other formats used in the construction of databases and text documents.

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

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

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

    "8. 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 Extended Backus-Naur Form (EBNF). This formal language, although quite difficult to understand, is devoid of ambiguity and greatly facilitates the writing of XML documents, and especially programs for processing them.

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

    The 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 point 6 (the XML document must be clear and understandable to the user), the XML markup should not be overly compressed so as not to conflict with the specified purpose.

    Standard XML Applications

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

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

    An XML application is typically defined by the creation of a document type descriptor (DTD), which is a valid component of the XML document. A DTD is built on a database schema: it establishes 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 used, and other features of the document. To actually use an XML application, you typically include its DTD in your XML document; Having a DTD in a document limits the elements and structures that you will use to ensure that your document meets the standards of that application. The XML document definitions discussed earlier in this chapter did not include DTDs. You'll learn how to define and use DTDs in Chapter 5.

    The benefits of using standard XML applications when developing your documents are that you can share the documents with all other users of the application, and the document can be processed and displayed using software that has already been built for the application.

    XML applications that improve the quality of XML documents

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

    • Extensible Stylesheet Language (XSL) allows you to create powerful stylesheets using XML syntax.
    • XML Schema allows you to develop detailed schemas for your XML documents using standard XML syntax, a more powerful alternative to using DTDs.
    • XML Linking Language (XLink) gives you the ability to link your XML documents. It supports multiple destination links and other useful features, providing greater freedom than HTML's linking mechanism.
    • XML Pointer Language (XPointer) allows you to define flexible target links. When XPointer and XLink are used together, you can link to anywhere in the target document - not just jumps to specific points.

    XLS will be covered in Chapter 10. Other XML applications are not yet mature 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 it also serves as the basis for building applications and extensions that may be in demand as the Internet evolves.

    Real Use of XML

    Although the concept of XML is quite interesting, you may be wondering how to put it into practice. This section provides a list of examples of such applications of XML, both already widely used and those in the future. If there are corresponding XML applications for practical use, they will be given in parentheses. For example, you may find that the MathML XML application will allow you to format mathematical formulas.

    Link. A more complete list of current and upcoming XML applications, including detailed descriptions, can be found on 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 every name, address, and phone number within an address list entry.) You can then display the data in a variety of ways and search, sort, filter, and otherwise manipulate 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 into acts, scenes, characters, plot lines, scenery, etc. XML markup allows programs to display or print the 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 ensure the distribution and updating of software products on the network (OSD - Open Software Description).
    • Application communication 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.
    • Exchange of financial information. Information is exchanged in an open and understandable format between financial programs (such as Quicken and Microsoft Money) and financial institutions (banks, public funds) (OFX - Open Financial Exchange).
    • Create, manage and use 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 job requests 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).
    • Encoding and displaying information about DNA, RNA and chains (BSML - Bioinformatic Sequence Markup Language).
    • Coding of genealogical data (GeDML - Genealogical Data Markup Language).
    • Astronomical data exchange (AML - Astronomical Markup Language).
    • 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, stock statements 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).
    • Filling out legal documents and electronic exchange of legal information (XCL - XML ​​Court Interface).
    • Coding of weather forecasts (OMF - Weather Observation Markup Format).
    • Exchange of information on real estate transactions (RETS - Real Estate Transaction Standard).
    • Exchange of insurance information.
    • Exchange news and information using open Web standards (XMLNews).
    • Presentation of religious information and markup of liturgical texts (ThML - Theological Markup Language, LitML - Liturgical Markup Language).






2024 gtavrl.ru.