Computers and modern gadgets

XML is increasingly used to store information and exchange it between applications and Web sites. Many applications use this language as a base language for storing data, while others use it for exporting and importing XML data. This means it's time for developers to think about how they can use XML data in their own applications.

In this article we will look at the XML Document Object Model (DOM) and its implementation by Microsoft - Microsoft XML DOM.

The XML DOM is an object model that provides the developer with objects for loading and processing XML files. The object model consists of the following main objects: XMLDOMDocument, XMLDOMNodeList, XMLDOMNode, XMLDOMNamedNodeMap, and XMLDOMParseError. Each of these objects (except XMLDOMParseError) contains properties and methods that allow you to obtain information about the object, manipulate the object's values ​​and structure, and navigate through the structure of the XML document.

Let's look at the main XML DOM objects and give some examples of their use in Borland Delphi.

Using XML DOM in Borland Delphi

In order to use the Microsoft XML DOM in Delphi applications, you need to connect the appropriate type library to the project. To do this, we execute the command Project | Import Type Library and in the Import Type Library dialog box, select the Microsoft XML version 2.0 library (Version 2.0), which is usually located in the file Windows\System\MSXML.DLL

After clicking the Create Unit button, the MSXML_TLB interface module will be created, which will allow us to use XML DOM objects: DOMDocument, XMLDocument, XMLHTTPRequest and a number of others implemented in the MSXML.DLL library. A reference to the MSXML_TLB module must be listed in the Uses list.

XML DOM device

The Document Object Model represents an XML document as a tree structure consisting of branches. XML DOM programming interfaces allow applications to navigate the document tree and manipulate its branches. Each branch can have a specific type (DOMNodeType), according to which the parent and child branches are determined. In most XML documents you will find branches like element, attribute and text. Attributes are a special kind of branch and are not child branches. Attributes are manipulated using special methods provided by XML DOM objects.

In addition to implementing World Wide Web Consortium (W3C) recommended interfaces, the Microsoft XML DOM contains methods that support XSL, XSL Patterns, Namespaces, and data types. For example, the SelectNodes method allows you to use XSL Pattern Syntax to find branches within a specific context, and the TransformNode method supports the use of XSL to perform transformations.

Test XML document

As an example of an XML document, let's take a directory of music CD-ROMs, which has the following structure:

Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tylor UK CBS Records 9.90 1988 ... Unchain my heart Joe Cocker USA EMI 8.20 1987

Now we're ready to start looking at the XML DOM object model, which we'll start with the XMLDOMDocument object.

XML document - XMLDOMDocument object

Working with an XML document begins with loading it. To do this, we use the Load method, which has only one parameter indicating the URL of the document to be loaded. When loading files from a local disk, only the full file name is specified (the file:/// protocol can be omitted in this case). If the XML document is stored as a string, you should use the LoadXML method to load the document.

To control how the document is loaded (synchronous or asynchronous), use the Async property. By default, this property is set to True, indicating that the document is loaded asynchronously and control is returned to the application before the document is fully loaded. Otherwise, the document is loaded synchronously, and then you have to check the value of the ReadyState property to find out whether the document has loaded or not. You can also create an OnReadyStateChange event handler that will receive control when the value of the ReadyState property changes.

The following shows how to load an XML document using the Load method:

Uses ... MSXML_TLB ... procedure TForm1.Button1Click(Sender: TObject); var XMLDoc: IXMLDOMDocument; begin XMLDoc:= CoDOMDocument.Create; XMLDoc.Async:= False; XMLDoc.Load('C:\DATA\DATA.xml'); // // Here is the code that manipulates // the XML document and its branches // XMLDoc:= Nil; end;

Once the document is loaded, we can access its properties. Thus, the NodeName property will contain the value #document, the NodeTypeString property will contain the value document, and the URL property will contain the value file:///C:/DATA/DATA.xml.

Error handling

Of particular interest are the properties associated with the processing of the document when it is loaded. Thus, the ParseError property returns an XMLDOMParseError object containing information about an error that occurred during document processing.

To write an error handler, you can add the following code:

Var XMLError: IXMLDOMParseError; ... XMLDoc.Load('C:\DATA\DATA.xml'); XMLError:= XMLDoc.ParseError; If XMLError.ErrorCode<>0 Then // // Here we handle the error // Else Memo1.Lines.Add(XMLDoc.XML); ... XMLDoc:= Nil;

To see what information is returned in case of an error, let's change the following directory entry:

Empire Burlesque Bob Dylan USA Columbia 10.90 1985

removing the closing element in the second line:</p><p> <CD> <TITLE>Empire Burlesque <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> </p><p>Now let's write code that returns the values ​​of the properties of the XMLDOMParseError object:</p><p>XMLError:= XMLDoc.ParseError; If XMLError.ErrorCode<>0 Then With XMLError, Memo1.Lines do begin Add(‘File: ‘ + URL); Add('Code: ' + IntToStr(ErrorCode)); Add(‘Error: ‘ + Reason); Add(‘Text: ‘ + SrcText); Add('Line: ' + IntToStr(Line)); Add(‘Position: ‘ + IntToStr(LinePos)); end Else Memo1.Lines.Add(XMLDoc.XML); End;</p><p>and let's run our application. As a result, we receive the following error information.</p> <p>As you can see from the above example, the information returned by the XMLDOMParseError object is quite enough to localize the error and understand the reason for its occurrence.</p> <p>Now let's restore the closing element <TITLE>in our document and continue our discussion of XML DOM.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h2>Accessing the Document Tree</h2> <p>To access a document tree, you can either get the root element and then iterate through its child branches, or find a specific branch. In the first case, we get the root element through the DocumentElement property, which returns an object of type XMLDOMNode. The following shows how to use the DocumentElement property to get the content of each child element:</p><p>Var Node: IXMLDOMNode; Root: IXMLDOMElement; I: Integer; ... Root:= XMLDoc.DocumentElement; For I:= 0 to Root.ChildNodes.Length-1 do Begin Node:= Root.ChildNodes.Item[I]; Memo1.Lines.Add(Node.Text); End;</p><p>For our XML document we will get the following text.</p> <p>If we are interested in a specific branch or a branch below the first child branch, we can use either the NodeFromID method or the GetElementByTagName method of the XMLDOMDocument object.</p> <p>The NodeFromID method requires a unique identifier defined in the XML Schema or Document Type Definition (DTD) and returns a branch with that identifier.</p> <p>The GetElementByTagName method requires specifying a string with a specific element (tag) and returns all branches with this element. Below is how to use this method to find all the artists in our CD-ROM directory:</p><p>Nodes: IXMLDOMNodeList; Node: IXMLDOMNode; ... Nodes:= XMLDoc.GetElementsByTagName('ARTIST'); For I:= 0 to Nodes.Length-1 do Begin Node:= Nodes.Item[I]; Memo1.Lines.Add(Node.Text); End;</p><p>For our XML document we will get the following text</p> <p>Note that the SelectNodes method of the XMLDOMNode object provides a more flexible way to access document branches. But more on that below.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h2>Document branch - XMLDOMNode object</h2> <p>An XMLDOMNode object represents a document branch. We already encountered this object when we got the root element of the document:</p><p>Root:= XMLDoc.DocumentElement;</p><p>To obtain information about the branch of an XML document, you can use the properties of the XMLDOMNode object (Table 1).</p> <p>To access data stored in a branch, you typically use either the NodeValue property (available for attributes, text branches, comments, processing instructions, and CDATA sections), the Text property, which returns the text content of the branch, or the NodeTypedValue property. The latter, however, can only be used for branches with typed elements.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h3>Navigating the document tree</h3> <p>The XMLDOMNode object provides many ways to navigate the document tree. For example, to access the parent branch the ParentNode property (XMLDOMNode type) is used, child branches are accessed through the ChildNodes (XMLDOMNodeList type), FirstChild and LastChild (XMLDOMNode type) properties, etc. The OwnerDocument property returns an object of type XMLDOMDocument that identifies the XML document itself. The properties listed above allow you to easily navigate the document tree.</p> <p>Now let's go through all the branches of the XML document:</p><p>Root:= XMLDoc.DocumentElement; For I:= 0 to Root.ChildNodes.Length-1 do Begin Node:= Root.ChildNodes.Item[I]; If Node.HasChildNodes Then GetChilds(Node,0); End;</p><p>As noted above, the XMLDOMNode object's SelectNodes provides a more flexible way to access document branches. In addition, there is a SelectSingleNode method that returns only the first branch of the document. Both of these methods allow you to specify XSL templates to search for branches.</p> <p>Let's walk through the process of using the SelectNodes method to retrieve all branches that have a CD branch and a PRICE subbranch:</p><p>Root:= XMLDoc.DocumentElement; Nodes:= Root.SelectNodes('CD/PRICE');</p><p>All PRICE sub-branches of the CD branch will be placed in the Nodes collection. We'll return to the discussion of XSL templates a little later.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h3>Manipulating Child Branches</h3> <p>To manipulate child branches, we can use the methods of the XMLDOMNode object (Table 2).</p> <p>In order to completely delete the entry for the first disk, you need to run the following code:</p><p>Var XMLDoc: IXMLDOMDocument; Root: IXMLDOMNode; Node: IXMLDOMNode; XMLDoc:= CoDOMDocument.Create; XMLDoc.Async:= False; XMLDoc.Load('C:\DATA\DATA.xml'); // Get the root element Root:= XMLDoc.DocumentElement; Node:= Root; // Remove the first child branch Node.RemoveChild(Node.FirstChild);</p><p>Note that in this example we are deleting the first child branch. How to remove the first element of the first child branch is shown below:</p><p>Var XMLDoc: IXMLDOMDocument; Root: IXMLDOMNode; Node: IXMLDOMNode; XMLDoc:= CoDOMDocument.Create; XMLDoc.Async:= False; XMLDoc.Load('C:\DATA\DATA.xml'); // Get the root element Root:= XMLDoc.DocumentElement; // and the first child branch Node:= Root.FirstChild; // Remove the first child branch Node.RemoveChild(Node.FirstChild);</p><p>In the above example, we deleted not the first branch <CD>…</CD>, and the first element of the branch is <TITLE>….

Now let's add a new branch. Below is the code showing how to add a new music CD-ROM entry:

Var NewNode: IXMLDOMNode; Child: IXMLDOMNode; ... // Create a new branch - NewNode:= XMLDoc.CreateNode(1, 'CD', ''); // Add an element Child:= XMLDoc.CreateNode(1,‘TITLE’,‘’); // Add an element NewNode.AppendChild(Child); // And set its value Child.Text:= 'Pink Floyd'; // Add an element <ARTIST>Child:= XMLDoc.CreateNode(1, 'ARTIST', ''); // Add an element NewNode.AppendChild(Child); // And set its value Child.Text:= 'Division Bell'; // Add an element <COUNTRY>Child:= XMLDoc.CreateNode(1, 'COUNTRY', ''); // Add an element NewNode.AppendChild(Child); // And set its value Child.Text:= 'UK'; // Add an element <COMPANY>Child:= XMLDoc.CreateNode(1, 'COMPANY', ''); // Add an element NewNode.AppendChild(Child); // And set its value Child.Text:= ‘EMI Records Ltd.’; // Add an element <PRICE>Child:= XMLDoc.CreateNode(1, 'PRICE', ''); // Add an element NewNode.AppendChild(Child); // And set its value Child.Text:= '11.99"; // Add an element <YEAR>Child:= XMLDoc.CreateNode(1, 'YEAR', ''); // Add an element NewNode.AppendChild(Child); // And set its value Child.Text:= '1994'; // And add a branch Root.AppendChild(NewNode); ...</p><p>The above code shows the following sequence of steps to add a new branch:</p> <ul><li>Creating a new branch using the CreateNode method: <ul><li>creating an element using the CreateNode method;</li> <li>adding an element to a branch using the AppendChild method;</li> <li>setting the element's value via the Text property;</li> <li>...repeat for all elements.</li> </ul></li> <li>Adding a new branch to a document using the AppendChild method.</li> </ul><p>Recall that the AppendChild method adds a branch to the end of the tree. In order to add a branch to a specific location in the tree, you must use the InsertBefore method.</p> <h2>Branch set - XMLDOMNodeList object</h2> <p>The XMLNodeList object contains a list of branches that can be built using the SelectNodes or GetElementsByTagName methods, or obtained from the ChildNodes property.</p> <p>We already looked at using this object in the example given in the section “Navigating the Document Tree”. Here we present some theoretical remarks.</p> <p>The number of branches in the list can be obtained as the value of the Length property. Branches have indexes from 0 to Length-1, and each individual branch is accessible through the Item array element with the corresponding index.</p> <p>Navigating through a list of branches can also be done using the NextNode method, which returns the next branch in the list, or Nil if the current branch is the last. To return to the beginning of the list, call the Reset method.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h2>Creating and saving documents</h2> <p>So far we've looked at how you can add branches and elements to existing XML documents. Now let's create an XML document on the fly. First of all, let us remind you that a document can be loaded not only from a URL, but also from a regular string. The following shows how to create a root element, which can then be used to dynamically build other elements (which we already covered in the Manipulating Child Branches section):</p><p>Var XMLDoc: IXMLDOMDocument; Root: IXMLDOMNode; Node: IXMLDOMNode; S: WideString; ... S:= ‘ <CATALOG></CATALOG>'; XMLDoc:= CoDOMDocument.Create; XMLDoc.Async:= False; XMLDoc.LoadXML(S); Root:= XMLDoc.DocumentElement; Node:= XMLDoc.CreateNode(1, 'CD', ''); Root.AppendChild(Node); Memo1.Lines.Add(XMLDoc.XML); ... XMLDoc:= Nil;</p><p>After constructing the XML document, we will save it in a file using the Save method. For example:</p> <p>XMLDoc.Save('C:\DATA\NEWCD.XML');</p> <p>In addition to saving to a file, the Save method allows you to save the XML document to a new XMLDOMDocument object. In this case, the document is completely processed and, as a result, its structure and syntax are checked. The following shows how to save a document in another object:</p><p>Procedure TForm1.Button2Click(Sender: TObject); var XMLDoc2: IXMLDOMDocument; begin XMLDoc2:= CoDOMDocument.Create; XMLDoc.Save(XMLDoc2); Memo2.Lines.Add(XMLDoc2.XML); ... XMLDoc2:= Nil; end;</p><p>Finally, note that the Save method also allows you to save an XML document to other COM objects that support the IStream, IPersistStream, or IPersistStreamInit interfaces.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h2>Using XSL Templates</h2> <p>When discussing the XMLDOMNode object's SelectNodes method, we mentioned that it provides a more flexible way to access document branches. The flexibility lies in the fact that you can specify an XSL template as a criterion for selecting branches. Such templates provide a powerful mechanism for searching information in XML documents. For example, to get a list of all the music CD-ROM titles in our catalog, you could run the following query:</p><p>To find out which artists' discs were released in the USA, the request is formed as follows:</p><p>Nodes:= Root.SelectNodes('CD/ARTIST');</p><p>The following shows how to find the first drive in the directory:</p><p>Nodes:= Root.SelectNodes('CD/TITLE');</p><p>And last:</p><p>Nodes:= Root.SelectNodes('CD/TITLE');</p><p>To find Bob Dylan CDs, you can run the following query:</p><p>Nodes:= Root.SelectNodes(‘CD[$any$ ARTIST= ”Bob Dylan”]/TITLE’);</p><p>and to get a list of discs released after 1985, we run the following query:</p><p>Nodes:= Root.SelectNodes('CD/TITLE');</p><p>A more detailed discussion of XSL syntax requires a separate post. To intrigue readers and encourage further research, I will give just one small example of possible uses of XSL. Let's say we need to convert our catalog into a regular HTML table. Using traditional methods, we must go through all the branches of the tree and form the appropriate tags for each element received <TD>…</TD>.</p> <p>Using XSL, we simply create a template (or style sheet) in which we indicate what needs to be converted and how. Then we overlay this template on our directory - and we’re done: we have the text of an XSL template that converts the directory into a table (Listing 2).</p> <p>The code for overlaying the XSL template on our directory looks like this:</p><p>Procedure TForm1.Button2Click(Sender: TObject); var XSLDoc: IXMLDOMDocument; begin XSLDoc:= CoDOMDocument.Create; XSLDoc.Load('C:\DATA\DATA.xsl'); Memo2.Text:= XMLDoc.TransformNode(XSLDoc); XSLDoc:= Nil; end;</p><p>Concluding our discussion of XSL, it should be said that currently this language is actively used for transformation between various XML documents, as well as for document formatting.</p> <table border="0" width="100%"><tr><td width="50%"> </td> <td width="50%"> </td> </tr></table><h2>Conclusion</h2> <p>For obvious reasons, it is impossible to review all Microsoft XML DOM objects and provide examples of their use in one article. Here we have only touched on the basic issues of using XML DOM in applications. In table Figure 3 shows all the objects implemented in the Microsoft XML DOM.</p> <p>ComputerPress 12"2000</p> <p>Many Delphi programmers associate saving settings with using <i>INI</i> files in your programs. The use of this method in less serious projects should be avoided, as it limits flexibility, which prevents further expansion of the program. It is worth saying that this approach is quite popular due to its ease of use and the availability of built-in tools in the development environment. <br><br>However, the ideal option for storing program settings is structured <i>XML</i> files. Their advantage is that the number of parameters may not be fixed. To better understand this, let's look at a specific example.</p><p>In the USearch program, when you click on an entry, a context menu appears, which displays a list of items. These items are commands, which in turn are loaded from the settings file. If the settings were stored in <i>INI</i> file, then the program could save and load a certain number of commands, for example 10 or 50. As soon as a larger value is needed, the code will have to be rewritten and recompiled accordingly.</p><p><img src='https://i2.wp.com/zoo-mania.ru/wp-content/uploads/2011/08/settings.ini_.jpg' height="145" width="247" loading=lazy loading=lazy><br>Using the approach using <i>XML</i> files, we will be able to load all section parameters dynamically. In addition to all this, the configuration file will become more elegant, without redundant numbering of parameters. However, standard tools for working with <i>XML</i> Delphi has many disadvantages, so I recommend using the standard library <b>MSXML</b>. It is usually included by default in the Windows family of operating systems.</p><p><img src='https://i1.wp.com/zoo-mania.ru/wp-content/uploads/2011/08/settings.xml_.jpg' align="center" width="100%" loading=lazy loading=lazy><br>To connect <b>MSXML</b>, we need to generate an interface file with a list of all functions, importing it from the COM server. There are quite a few detailed articles written on how to import an interface, but I suggest you download the file <b>MSXML2_TLB.PAS</b> already ready to use. After the file is downloaded, place it next to your project, or drop it into the lib folder of the Delphi environment. Thus, all created programs will be able to use the module <b>MSXML</b>, you just need to add the line MSXML2_TLB to uses.</p><p>For clarity, consider the following example of using this library:</p><p>Procedure LoadData; var XMLDoc: DOMDocument; Root: IXMLDOMElement; begin XMLDoc:= CoDOMDocument.Create; XMLDoc.Load("settins.xml"); Root:= XMLDoc.DocumentElement; ShowMessage(Root.SelectSingleNode("size/width").Text); Root:= nil; XMLDoc:= nil; end;</p><p>First, an instance of the DOMDocument class is created, and then the contents of the settings.xml file are loaded into memory. Since according to the standard any <i>XML</i> the file must contain a root tag (in this case <i>config</i>), then we need to get it using the function <i>DocumentElement</i>. Then the content between the tags is output <width></width>, which in turn are located between the tags <size></size>. Thus, from the settings.xml file, our method will display text in the MessageBox <i>"100px"</i>.</p><p> <?xml version="1.0" encoding="utf-8"?> <config> <size> <height>500px</height> <width>100px</width> </size> </config> </p><p>The SelectSingleNode method is used here, which takes a string as a parameter</p> <p>Welcome! This blog is dedicated to the Internet and computers, or rather was dedicated to them.</p> <p>It’s probably immediately obvious that no new articles have appeared on the site for many years. Yes, this is the fate of most blogs. This project was once an ambitious undertaking, and the author, like many others writing at the time, had ambitious plans to become one of the best Russian bloggers. Well, if you look now, of those blogs that were created simultaneously with mine, most have already disappeared into eternity. And I just simply didn’t have enough time to blog. So yeah, it's not updated anymore. Although we once won the “Runet Blog 2011” competition with this site.</p> <p>I even had the idea of ​​deleting all this, but then I reviewed the old materials and realized that they could still be useful to readers. Yes, some articles are outdated (if I have enough strength, they will be marked accordingly), but the site, for example, can be useful for beginners - here you can read about the basic concepts of the Internet, learn how to set up the Internet, Windows, or even decide to switch to Linux. So take a look at the categories and choose the one that suits you.</p> <p>And yet, I hope that this is more than just a blog, but a real guide to the Internet. The site can be viewed in directory mode, where all available articles are structured by categories. And, who knows, maybe one day new high-quality articles will start appearing here.</p> <p><i>Sander</i></p> <p>Picodi.ru is a discount portal from International Coupons, a Polish expert in the field of savings and cheap shopping. The Poles are considered one of the most frugal nations in the world, so it is not surprising that this type of project grew out of the Polish startup kodyrabatowe.pl. How can this portal be useful to the average Internet user in Russia?</p> <p>Modern Android phones are more than just phones. You get used to the set of installed programs, the history of your calls and text messages, your collection of photos and much more. But time passes, and the device that you were completely satisfied with begins to slow down, glitch, or simply loses its presentable appearance due to chips on the body or scratches on the screen. The question arises of choosing a new phone and changing the Android phone. And if we ignore the issue of choice for now, then “moving” to a new phone remains a serious problem - you absolutely don’t want to start all the data from scratch. This is what we will talk about today.</p> <p>Most of the readers of this blog have most likely never encountered version control systems and will not encounter them in the near future. It's a pity. This extremely convenient invention is quite widely used by programmers, but, in my opinion, it could also be very useful for those who actively work with texts. But, probably, now there is not a single version control system that would be easy to start using for “office” (Microsoft Office) work. Nevertheless, I think that the material presented in the article may be of interest to all readers.</p> <p>If you have been wondering how to watch movies online and access the Internet from your TV, this article is for you. No, I know that some TVs already have Smart TV functionality, but I have never seen it work properly. Apparently, this is why Google recently demonstrated an absolutely stunning device that immediately became a sensation. We're talking about the Chromecast media streamer, a more advanced and affordable version of last year's disastrous Nexus Q player.</p> <p>The Chromecast dongle, whose dimensions do not exceed 2 inches, connects to the HDMI port of the TV and allows you to enjoy watching streaming web content. To control the streamer, you can use any device (tablet, PC, smartphone) based on the operating platform iOS, Windows, Android or Mac OS.</p> <p>This article is devoted to the design of Android system memory, problems that may arise due to its lack and ways to solve them. I myself recently encountered the fact that my Android phone began to regularly display messages about low memory when I tried to install this or that application. Which was very strange for me, given that according to the description on the market there should have been about 16GB, and I also increased this volume using an additional memory card. However, there was a problem, and it took a lot of fiddling around before I found the right solution that didn’t require root access or completely restoring the phone to its factory state.</p> <p>Recently, a lot of attention has been paid to building e-business systems, or as they are also called - B2B (business to business). Taking into account the recommendations for the construction of exchange streaming systems of the body coordinating Internet technologies - WWW Consortium: the emphasis is placed on XML technologies and the construction of XML document exchange systems.</p> <p>The advantage of using XML in electronic business is the high efficiency of B2B systems at low costs of its creation due to a clear and visual presentation of structured information, the ability to use modern network protocols and create real-time business systems.</p> <p>The independence of presenting information in the form of XML documents allows different companies participating in electronic business to produce software independent of each other.</p> <p>In all systems, exchange is usually built according to the same scheme, using HTTP requests. The SSL protocol is used as an information security protocol (but this is a separate topic).</p> <p>One of the possible options for processing XML messages is to build BIN/CGI (ISAPI) applications or COM (server) components that generate or process XML documents.</p> <p>On the one hand, the application acts as a client that issues an HTTP request in POST mode, on the other hand, there is a WEB server on whose side the request is processed and the response is issued. XML documents are used in information exchange.</p> <p>One of the most effective implementation options is to use an existing XML parser that supports the DOM model. This parser is a distribution package of Win`98 or a component of IE 4.7 and higher (for Win`95) and represents a COM server located in the msxml.dll library.</p> <p>Component Object Model (COM) - represents encapsulated data and methods into a single entity and a way to access them through a system of interfaces. Using Delphi, it is quite easy to access the classes of a COM object (several classes can be included in one COM server). Objects are accessed by initializing an instance of the class through a system of interfaces. The description of interfaces is carried out by the Interface Definition Language (IDL), which can be done automatically using the environment.</p> <p>Delphi tools import from a COM server <i>msxml.dll</i>, IDL interface description files and a binary description file of library types - TLB - are built. This operation is carried out through the system menu: <b>Project | Type Library Import:</b>(picture 1). Next, a dialog box appears (Figure 2), in which you need to select a COM object (in our case, the object is registered under the name "Microsoft.XMLDom (Version 2.0)") and create a TLB file (button <b>Create Unit</b>). Using the TLB file, the environment generates a "Pascal" COM server description file - MSXML_TLB.pas</p> <p>The MSXML_TLB.pas file describes all interfaces, constants and co-classes of the COM server.</p> <p>To access COM element objects, it is necessary in the directive <b>USES</b> add the name of the library description file (MSXML_TLB.pas). Below is a simple program that uses the standard DOM parser msxml.dll, which loads an XML document and displays it in the Memo1 text field element.</p> <b>uses</b> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, OleServer, MSXML_TLB, StdCtrls; <b>type</b> TForm1 = <b>class</b>(TForm)Button1: TButton; Memo1: TMemo; <b>procedure</b> Button1Click(Sender: TObject); <b>end;</b> <b>var</b> Form1: TForm1; <b>implementation</b>($R *.DFM) <b>Procedure</b> TForm1.Button1Click(Sender: Tobject); <span>// declaration of a coclass of the DOMDocument object;</span> <b>var</b> coDoc: CoDOMDocument; <span>// class consistent with the IDOMDocument interface;</span> <b>var</b> Doc: IXMLDOMDocument; <b>begin</b> <span>// creating an instance of a DOMDocument object;</span> Doc:= coDoc.Create; <span>// calling the Load method of a DOMDocument object instance;</span> Doc.load("data.xml"); <span>// access to the xml property of the DOMDocument object instance;</span> Memo1.Text:=Doc.xml; <b>end;</b> <b>end.</b> <h2>Concept of DOM - Document Object Model</h2> <p>Each XML document is represented as a set of many objects (classes), with the help of which access to individual elements (object fields) is possible. DOM - interface describes access to both simple objects of the DOMString or CharacterData type, and to parts or individual elements of an XML document: DOMFragmentElement, DOMNode, DOMElement.</p> <p>Below are the most important properties and methods of the XMLDOMNode, XMLDOMNode, XMLDOMNodeList objects. It should be noted that the methods and functions of DOM objects (Document Object Model) presented below are used by the Microsoft XML parser msxml.dll and are somewhat broader than the DOM model approved by the W3C Consortium.</p> <p>A more complete description of the DOM object interface can be found at</p> <table cellspacing="0" cellpadding="4" width="500" border="1"><tbody><tr><td valign="top" colspan="2">XMLDOMDocument object</td> </tr><tr><td valign="top" colspan="2">Represents the top level of the object hierarchy and contains methods for working with a document: loading it, analyzing it, creating elements, attributes, comments in it, etc. .</td> </tr><tr><td valign="top" colspan="2"><b>Properties</b> </td> </tr><tr><td valign="top" width="39%"><b>Async</b> </td> <td valign="top" width="61%">Property identifying the current processing mode</td> </tr><tr><td valign="top" width="39%" height="19"><b>ParseError</b> </td> <td valign="top" width="61%" height="19">Returns a reference to the XMLDOMParseError error handling object</td> </tr><tr><td valign="top" width="39%"><b>Enable - disable document verification.</b> </td> <td> </td> </tr><tr><td valign="top" width="39%"><b>url</b> </td> <td valign="top" width="61%">Returns the URL of the document</td> </tr><tr><td valign="top" width="39%"><b>documentElement</b> </td> <td valign="top" width="61%">Contains a reference to the root element of the document as an XMLDOMElement object.</td> </tr><tr><td valign="top" colspan="2"><b>Methods</b> </td> </tr><tr><td valign="top" width="39%"><b>load(url) <br>loadXML(xmlString)</b> </td> <td valign="top" width="61%">Loads an XML document,</td> </tr><tr><td valign="top" width="39%"><b>save(objTarget)</b> </td> <td valign="top" width="61%">Saves an XML document to a file</td> </tr><tr><td valign="top" width="39%"><b>abortion</b> </td> <td valign="top" width="61%">Interrupting the document loading and processing process.</td> </tr><tr><td valign="top" width="39%"><b>createAttribute(name)</b> </td> <td valign="top" width="61%">Creates a new attribute with the specified name for the current element.</td> </tr><tr><td valign="top" width="39%"><b>createNode(Type, name, nameSpaceURI)</b> </td> <td valign="top" width="61%">Creates a node of the specified type and name</td> </tr><tr><td valign="top" width="39%"><b>createElement(tagName)</b> </td> <td valign="top" width="61%">Creates a document element with the specified name.</td> </tr><tr><td valign="top" width="39%"><b>createTextNode(data)</b> </td> <td valign="top" width="61%">Creates text inside a document</td> </tr><tr><td valign="top" width="39%"><b>getElementsByTagName(tagname)</b> </td> <td valign="top" width="61%">Returns a reference to a collection of document elements with the given name</td> </tr><tr><td valign="top" width="39%"><b>nodeFromID(idString)</b> </td> <td valign="top" width="61%">Searching for an element by ID</td> </tr></tbody></table><br><table cellspacing="0" cellpadding="4" width="500" border="1"><tbody><tr><td valign="top" colspan="2"> <b>XMLDOMNode object</b> </td> </tr><tr><td valign="top" colspan="2">An XMLDOMNode object that implements the basic DOM interface <b>Node</b>, is intended for manipulating a single node of the document tree. Its properties and methods allow you to obtain and change complete information about the current node - its type, name, full name, its contents, list of child elements, etc.</td> </tr><tr><td valign="top" colspan="2"><b>Properties</b> </td> </tr><tr><td valign="top" width=" "><b>nodeName, baseName</b> </td> <td valign="top" width="65%">Returns the name of the current node.</td> </tr><tr><td valign="top" width="35%"><b>prefix</b> </td> <td valign="top" width="65%">Returns the Namespace prefix.</td> </tr><tr><td valign="top" width="35%"><b>dataType</b> </td> <td valign="top" width="65%">Determines the content type of the current node</td> </tr><tr><td valign="top" width="35%"><b>nodeType, nodeTypeString</b> </td> <td valign="top" width="65%">Returns the type of the current node:</td> </tr><tr><td valign="top" width="35%"><b>attributes</b> </td> <td valign="top" width="65%">Returns a list of attributes of the current node as a collection of XMLDOMNamedNodeMap.</td> </tr><tr><td valign="top" width="35%"><b>text</b> </td> <td valign="top" width="65%">Returns the contents of the current subtree as text</td> </tr><tr><td valign="top" width="35%"><b>xml</b> </td> <td valign="top" width="65%">Returns an XML representation of the current subtree.</td> </tr><tr><td valign="top" width="35%"><b>nodeValue</b> </td> <td valign="top" width="65%">Returns the contents of the current node.</td> </tr><tr><td valign="top" width="35%"><b>childNodes</b> </td> <td valign="top" width="65%">Returns a list of child elements as an XMLDOMNodeList.</td> </tr><tr><td valign="top" width="35%"><b>firstChild, lastChild</b> </td> <td valign="top" width="65%">Returns the first/last child element</td> </tr><tr><td valign="top" width="35%"><b>previousSibling ,nextSibling</b> </td> <td valign="top" width="65%">Returns the previous/next sibling element.</td> </tr><tr><td valign="top" width="35%"><b>parentNode</b> </td> <td valign="top" width="65%">Contains a link to the parent element.</td> </tr><tr><td valign="top" width="35%"><b>ownerDocument</b> </td> <td valign="top" width="65%">Returns a pointer to the document in which the current node is located.</td> </tr><tr><td valign="top" colspan="2"><b>Methods</b> </td> </tr><tr><td valign="top" width="35%"><b>appendChild(newChild)</b> </td> <td valign="top" width="65%">Adds a new child element to the current node.</td> </tr><tr><td valign="top" width="35%"><b>insertBefore(newChild, refChild)</b> </td> <td valign="top" width="65%">Inserts a child node, positioning it in the current subtree "to the left" of the node specified by the refChild parameter.</td> </tr><tr><td valign="top" width="35%"><b>cloneNode(deep)</b> </td> <td valign="top" width="65%">Create a copy of the current element.</td> </tr><tr><td valign="top" width="35%"><b>getAttribute</b><b>(name) <br> </b><b>getAttributeNode</b><b><span>(name) <br>setAttribute(name, value) <br>setAttributeNode(XMLDOMAttribute)</span> </b> </td> <td valign="top" width="65%">Access to attributes (create, read, write) of an object. Name is the name of the attribute, value is its value. Returns the value of an XMLDOMAttribute object.</td> </tr><tr><td valign="top" width="35%"><b>replaceChild(newChild, oldChild) removeChild(oldChild)</b> </td> <td valign="top" width="65%">Replaces the oldChild object of the current list of child objects with newChild. Deleting the oldChild object</td> </tr><tr><td valign="top" width="35%"><b>selectNodes(patternString) selectSingleNode(patternString)</b> </td> <td valign="top" width="65%">Returns the XMLDOMNodeList object selected by the search pattern or the first node</td> </tr><tr><td valign="top" width="35%"><b>transformNode(stylesheet) <br>transformNodeToObject(stylesheet, outputObject)</b> </td> <td valign="top" width="65%">Assigns a style sheet to the subtree of the current node and returns a string - the result of processing. A reference to the DOMDocument object containing XSL instructions is passed as a parameter.</td> </tr></tbody></table><br><h2>Using XML in business.</h2> <p>For a clearer picture, an explanation is needed as to why all this is needed in order to understand how it works:</p> <p>When building a B2B or corporate ERP system, when organizing information exchange of XML documents between enterprises or branches of a company, an effectively proven information transfer system is used based on existing WEB servers via HTTP protocols.</p> <p>On the one hand, the application acts as a client, which issues an HTTP request in POST mode; on the other hand, there is a WEB server, on whose side the request is processed and the response is issued. XML documents are used as exchange.</p> <p>For example, in a simple corporate ERP system, an accounting program (ASU Bukhuchet) needs to generate a certain request for issuing an invoice and transfer it to a branch that has a warehouse (ASU Warehouse). AWP A similar formulation of the problem when creating a B2B system, when Enterprise A requests the availability of products (places a purchase order) from Supplier B.</p> <p>Enterprise A and its program act as a client. The warehouse is maintained by Supplier B, who has a warehouse database complex on a SQL server. The exchange is carried out through the corporate WEB server of Supplier B.</p> <p>The following typical exchange algorithm is presented below:</p> <br>Figure 3. <ol><li><b>Enterprise A</b> initiates <b>process A</b>(product order), which acts as a WEB client.</li><li><b>Process A</b> generates an XML document (for example, an invoice request) and transmits it as a POST http request to the WEB server of Supplier B. The resource identifier of the processing application is used as a URI. The URI can be the same for all types of documents, or individual for each type. It all depends on the structure of the B2B (WEB) server.</li><li>WEB server analyzes the request and generates a server <b>Process B</b>, passing the body of the XML document as a parameter. <br>Process B is launched by the WEB server and processed either as an ASP page, a CGI (ISAPI) application or a JAVA serverlet (server application)</li><li><b>Process B</b>- generates a request to the SQL database server.</li><li>The SQL server performs the necessary operations in the database, generates a response and returns it <b>Process B</b>.</li><li>Based on the response from the SQL server <b>Process B</b> generates an XML document (response) and returns it as a response to an http request to the client application.</li><li>Next, depending on the situation on the client side, either a new http request is generated or the session ends.</li> </ol><h2>A few words about the organization of document flow.</h2> <p>The general rule for developing an XML document exchange system is:</p><ul><li><b>Firstly</b>- development of a flow diagram of electronic documents and their structure;</li><li><b>Secondly</b>- development of tables of process functions (subprocesses), i.e. which function in relation to which XML document each process will implement.</li> </ul><p>Each XML document, like an HTML document, must consist of a message header (information enclosed in tags) and a message body (for a request, this information is enclosed in tags to respond to the request). In order for the XML document to be correctly formed, it is necessary to frame its two components “Header” and “Request” with tags, for example. The type of standard document is presented below:</p> <p>The header (Figure 4), unlike an HTML document, must contain various types of service information, including information about the type of document being transmitted and the process of its processing. The body of the document enters information processing, i.e. content framed by tags. It should be noted that the structure of headings must be the same for all types of documents.</p> <p>For a Process launched by the server, the processing algorithm is preferably (but not necessarily) constructed as follows:</p> <img src='https://i2.wp.com/codenet.ru/np-includes/upload/2005/01/05/128666.jpg' height="500" width="408" loading=lazy loading=lazy><br>Figure 6. <h2>Some fundamental points when creating the client part</h2> <p>As already explained, when creating an XML document, its representation in the form of a DOM model is used. Below is an example of part of the Delphi text of the program for creating an xml message header.</p> <b>procedure</b> TThread1.HeaderCreate(Sender: Tobject); <b>var</b> <span>// declaration of a coclass, required to create</span> coDoc: CoDomDocument; <span>// XMLDomDocument object</span> Doc: DomDocument; r: IXMLDOMElement; Node: IXMLDOMElement; // DOMText txt: IXMLDOMText; // DOMAttribute attr: IXMLDOMAttribute; <b>begin</b> <span>// creating a DOM document</span> Doc:=coDoc.Create; Doc.Set_async(false); <span>// initial initiation of the DOM document</span> Doc.LoadXML(" <Header/>"); <span>// creating DOMElement (tag<<b>Sender</b>>) </span> Node:= Doc.createElement("Sender"); <span>// create a text node " <b>LLC "Typhoon"</b>" </span> txt:= Doc.createTextNode("Typhoon LLC"); <span>// assignment to node<<b>Sender</b>> value</span> <span>// text node " <b>LLC "Typhoon"</b>" </span> Node.appendChild(txt); <span>// adding an element<<b>Sender</b>> to the root of the document as a child</span> r.appendChild(Node); <span> <<b>From</b>> </span> Node:= Doc.createElement("From"); txt:= Doc.createTextNode("http://tayfun.ru/xml/default.asp"); Node.appendChild(txt); r.appendChild(Node); <span>// similar operations for tag<<b>To</b>> </span> Node:= Doc.createElement("To"); txt:= Doc.createTextNode("http://irbis.ru"); Node.appendChild(txt); r.appendChild(Node); <span>// create DOMElement()</span> Node:= Doc.createElement("TypeDocument"); <span>// creating an XMLDOMAttribute node</span> Att:= Doc.createAttribute("Id", "Order"); <span> // <TypeDocument Id="Order"/> </span> Node.appendChild(Att); r.appendChild(Node); <b>end;</b> <p>It should be noted that the declaration of the variable coDoc: CoDomDocument and Doc: DomDocument , as well as its creation by the Create method (Doc:=coDoc.Create;) is carried out once. The variable declaration is located in the global variable declaration section, and not in the local procedure, as was demonstrated for clarity in this example (i.e., one global variable of type DomDocument per program module).</p> <p>The result of the above program will be the created header, in relation to our example xml document: shown in Figure 5.</p> <img src='https://i1.wp.com/codenet.ru/np-includes/upload/2005/01/05/128662.gif' height="116" width="298" loading=lazy loading=lazy><br>Figure 5. <p><img src='https://i2.wp.com/codenet.ru/np-includes/upload/2005/01/05/128664.gif' height="179" width="385" loading=lazy loading=lazy><br>Figure 6.</p><p>The main advantage of transmitting information in the form of XML documents is that it is possible to generate a message using independent table structures in the DBMS on both the receiving and transmitting sides. Using our example, let’s say you need to transfer information about invoices of Enterprise A from a DBMS having the structure shown in Figure 6</p> <p>To generate an xml document containing an invoice, an SQL query (query A) is initially built with information about the invoice itself:</p> <b>SELECT</b>* FROM Invoice_General <b>WHERE</b> InvoiceNum = :num <b>SELECT</b> Goods,Quality,Price, HZ_cod <b>FROM</b> Goods <b>WHERE</b> InvoiceNum = :num <span>// :num - parameter that specifies the invoice number.</span> <p>Below is part of the program that forms the body of the xml document:</p> <b>procedure</b> TThread1.DataBodyCreate(Sender: Tobject); <b>var</b> <span>// declaration of a coclass and an XMLDomDocument object</span>//coDoc: CoDomDocument ; <span>// must be global for the entire module.</span>//Doc: DomDocument ; <span>// declaration of DOMElement objects</span> r: IXMLDOMElement; // DOMElement; Node, Node2: IXMLDOMElement; Node3, Node4: IXMLDOMElement; // DOMText txt: IXMLDOMText; str: String; <span>// InvoiceNumber: <b>integer;</b>- global variable - // has the value 987654 // queryA, queryB: <b>String;</b>- global variable, // has a value corresponding to the request // queryA - request A general information about the invoice // queryB - request B information about the goods described in // the invoice (see text)</span> <b>begin</b> Query.Close; <span>// see the text "query A"</span> Query.Text:= queryA; <span>// execute the request</span> Query.ExecSQL; Query.Open; <span>// getting the address of the root element</span> r:=Doc.Get_documentElement; Node2:= Doc.createElement("Request"); <span>// create DOMElement (tag)</span> Node:= Doc.createElement("Invoice"); <span>// adding an element to the root</span> r.appendChild(Node2); <span>// adding an element to</span> Node2. appendChild(Node); <span>// create DOMElement (tag)</span> Node3:= Doc.createElement("Depurture"); <span>// adding an element to</span> Node. appendChild(Node3); <span>// access to the "Depurture" field of the request</span> str:= Query.FieldByName("Depurture").AsString; <span>// creating a text node = field value</span><span>// assigning a value to the node</span> <span>// text node, variable str</span> Node.appendChild(txt); <span>// similar operations for tag <Destination>, <DataSend>, // <DataDepurture>, <Currency> // <DestinationCompany>(DB field "Consignee")</span> Node:= Doc.createElement("Destination"); <span>// the name of the database field may not coincide with the name</span> str:= Query.FieldByName("Consignee ").AsString; <span>// tag, this is the advantage of using</span> txt:= Doc.createTextNode(str); <span>// DOM of the interface in front of a DBMS that supports an XML interface, // like ORACLE 8i or Ms SQL 2000</span> Node.appendChild(txt); ... <span>// generating a request for specifications for goods</span> <span>// closes the access request</span> Query.Close; <span>// see in the text "request B", information. About products</span> Query.Text:= queryВ; <span>// assigning parameter values</span> Query.Params.AsInteger:= InvoiceNumber; <span>// execute the request</span> Query2.ExecSQL; <span>// opening access to request data</span> Query.Open; <span>// create DOMElement (tag)</span> Node3:= Doc.createElement("Imems"); <span>// adding an element to</span> Node. appendChild(Node3); <span>// loop through all query lines</span> <b>while</b> <b>not</b> Eof.Query <b>do</b> begin Node4:= Doc.createElement("Imem"); <span>// adding an element to</span> Node3.appendChild(Node4); <span>// generating data for the tag</span> str:= Query.FieldByName("Price").AsString; txt:= Doc.createTextNode(str); Node.appendChild(txt); ... <span>// similar operations for tags <HZ_Cod>, <Quality>, <GoodName> </span> <b>end;</b> <b>end;</b> <p>As a result of this procedure, the following text of the XML document is generated:</p> <table width="100%"><tbody><tr><td align="middle"><br><img src='https://i1.wp.com/codenet.ru/np-includes/upload/2005/01/05/128661.gif' width="100%" loading=lazy loading=lazy></td> </tr></tbody></table><p>To form a request, the Open method of the object is used <b>IXMLHttpRequest</b>:</p> <b>procedure</b> Open(const bstrMethod, - method type ="POST" bstrUrl, - Url server address varAsync, - communication mode asynchronous/synchronous = true bstrUser, - username for authentication bstrPassword) - password <h2>Creating a document processing server part</h2> <p>As noted earlier, HTTP request processing can be done by either CGI applications or Java servlets. It is also possible to write ASP pages. But in this case, data transfer is only possible using the "GET" method via a query string. Although, HTTP request processing for ASP pages is more efficient than for a CGI application. However, in my opinion, it makes no difference how to process, but what is more important is to solve the question - how to build a processing program, and not by what means.</p> <p>If from the previous chapter we looked at options for generating an XML document, then the task of the server application is the opposite - parsing XML documents. Below is a part of the program that parses the xml document:</p> <b>procedure</b> Tthread1.DataParser(Sender: Tobject); <b>var</b> <span>// declaration of DOMElement objects</span> r,FNode: IXMLDOMElement; Str, Filename: String; parm: String; <span>// declaration of a coclass and</span> CoDocXML, CoDocXSL, CoDocResult: CoDomDocument ; <span>// XMLDomDocument object</span> XMLDoc, XSLDoc, ResultDoc: DomDocument ; <span>// HttpStr: String; - global variable containing the HTTP request string</span> <b>Begin</b> XMLDoc:=coDocXML.Create; XMLDoc.LoadXML(HttpStr); <span>// getting the address of the root element</span> r:=Doc.Get_documentElement; <span>// getting the element's value</span> FNode:= r.SelectSingleNode("//TypeDocument"); <span>// getting the attribute value id="Order"</span> FileName:= FNode.GetAttibute("id"); <span>// and forming the file name Order.xsl</span> FileName:= FileName+".xsl"; <span>// create an XSLDoc document</span> XSLDoc:=coDocXSL.Create; XSLDoc.LoadXML(FileName); <span>// create an XMLDoc document</span> ResultDoc:=coDocResult.Create; <span>// setting the synchronous processing mode</span> ResultDoc.Set_async(false); <span>// set parsing check</span> ResultDoc.validateOnParse:= true; <span>// parse XMLDoc using an XSL template</span> XMLDoc.transformNodeToObject(XSLDoc, ResultDoc); <span>// variable Str is assigned a text value</span> <span>// the resulting document.</span> Str:= ResultDoc.text; <span>// search for element</span> FNode:= r.SelectSingleNode("//InvoiceNumber"); <span>// and getting the element's value</span> parm:= FNode.text; <span>// closes the access request</span> Query.Close; Query.Text:= Str; <span>// assigning a parameter value</span> Query.Params.AsString:= parm; <span>// execute the request</span> Query.ExecSQL; <b>end;</b> <p>The whole highlight of the analysis is the use of an XSL template, which is generated individually for each type of document. The result of parsing is a SQL query string. Subsequently, executing the generated SQL query string will make the necessary changes to the data in the DBMS.</p> <p>The advantage of using parsing through a template is that the data is somewhat flexible, and the operation of the algorithm is completely independent of the program code. Below is the XSL template text used to process an ORDER document:</p><p> <!-- файл Order.xsl --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <xsl:for-each select="//header">INSERT into TABREG (FROM, TO, TYPEDOC,body) VALUES(" <xsl:value-of select="from" />", "<xsl:value-of select="to" />", "<xsl:value-of select="TypeDocument/@id" />") </xsl:for-each> <xsl:for-each select="//item">INSERT into GOODS (invoiceNumber, name, price, quality) VALUES(" :num", " <xsl:value-of select="name" />", "<xsl:value-of select="price" />", "<xsl:value-of select="quality" /> ") </xsl:for-each> </xsl:template> </xsl:stylesheet> </p><p>Explaining the above example, it should be noted that the use of a pair of tags is of a formal nature, because after parsing, the resulting XML document must formally contain at least one node. The ResultDoc.text method assigns the text value of the ResultDoc XML document obtained during parsing. In this case, the value is everything that is framed by a pair of tags and, i.e. The SQL query we generated.</p> <p>Another feature of writing a program is the possibility of using an SQL parameter <b>:num.</b> Using this parameter allows you to simplify the text of the xsl template. Determining the meaning of the corresponding node elements of an XML document is determined by initially selecting the name of the corresponding node, for example:</p><h2>Briefly about XSL</h2> <p>The abbreviation XSL comes from eXtensible Stylesheet Language - a language for formatting style sheets (XML data). As the title suggests, eXtensible Stylesheet Language (XSL) is used to format XML data. By W3C definition, XSL consists of two parts:</p> <ul><li>XSLT - XSL Transformation. A language used to convert or format (transform) XML documents. Thus, with the help of XSLT we can get different sections of the data set and forms of data presentation.</li><li>Formatting elements. These elements include all elements of the typographic design of the data, after they have been processed using XSL. Used only to generate HTML pages.</li> </ul><p>Using XSLT, we can select the data we need from an XML file and arrange it in a form for presentation to the user. For example, in our case, we converted XML data into an SQL query. The classic use of XSL is, as a rule, formatting data in the form of HTML pages or, more rarely, in the form of RTF files.</p> <p>The XSL file describes the template according to which the XML data will be converted. Returning to xsl templates, the following elements (directives) can be distinguished in XSLT:</p> <table cellspacing="0" cellpadding="4" width="500" border="1"><tbody><tr><td valign="top" width="31%"> <b>XSL directives</b> </td><th align="middle" width="69%"> <b>description</b> </th> </tr><tr><td>xsl:apply-templates</td> <td>Directive indicating the application of the corresponding templates to the select="template name" attribute</td> </tr><tr><td>xsl:attribute</td> <td>creates an attribute tree and adds it to the output element, parameter name="attribute name", namespace - URI to the namespace (namespace prefix)</td> </tr><tr><td>xsl:call-template</td> <td>calls the template, attribute name="URI to template"</td> </tr><tr><td>xsl:choose <br>xsl:when <br>xsl:otherwise</td> <td>making a selection based on xsl:when expr="evaluating an expression in a script", <br>language="language-name" <br>test= "evaluated expression"</td> </tr><tr><td>xsl:comment</td> <td>generates a comment in the output document</td> </tr><tr><td>xsl:copy <br>xsl:copy-of</td> <td>copies the current node to the output source or pastes a document fragment into the node where the select attribute = "source node name"</td> </tr><tr><td>xsl:element</td> <td>creates an output element by name, attribute name="element name", namespace="uri namespace reference"</td> </tr><tr><td>xsl:for-each</td> <td>reapplies the template to all nodes in the node list, the select attribute specifies the list of nodes</td> </tr><tr><td>xsl:if</td> <td>checking the condition, specified by the test attribute as an expression</td> </tr><tr><td>xsl:include</td> <td>includes external template, href = "URI reference" attribute</td> </tr><tr><td>xsl:output</td> <td>specifies the output result, the method attribute can have the values ​​"xml", "html" or "text"</td> </tr><tr><td>xsl:param</td> <td>specifies the value of the parameters, attribute name="parameter name", select = "value"</td> </tr><tr><td>xsl:processing-instruction</td> <td>creates a processing instruction, attribute name="process instruction name"</td> </tr><tr><td>xsl:sort</td> <td>sorts multiple nodes, attributes select = "node name", data-type = data type ("text" | "number" | Qname), order = sort direction ("ascending" | "descending")</td> </tr><tr><td>xsl:stylesheet</td> <td>defines an xsl template document, is the root element for XSLT</td> </tr><tr><td>xsl:template</td> <td>defines an xsl template, attribute name= "URI prefix to the template name", match= "indication of the node to which the template is applied"</td> </tr><tr><td>xsl:text</td> <td>generates text into the output stream, the disable-output-escaping attribute = "yes" or "no", indicates the ability to generate ESC characters</td> </tr><tr><td>xsl:value-of</td> <td>inserts the value of the selected node as text, the select attribute = "pointer to node" from which the value is taken</td> </tr><tr><td>xsl:variable</td> <td>specifies the value of variable boundaries, attribute name = "variable name", select = "calculation of variable value"</td> </tr><tr><td>xsl:with-param</td> <td>applies a parameter to a template, name attribute = "parameter name", select = expression to evaluate the current context, default value "."</td> </tr></tbody></table><h2>Conclusion</h2> <p>Finally, it should be noted that using a standard XML parser <i>msxml.dll</i> is not the only tool for parsing and creating XML documents. For example, to create XML documents it is effective to use components <b>TPageProduser</b> And <b>TTableProduser</b>. But, this article only emphasizes the breadth and possibility of using the DOM model in practice.</p> <p>The author will be very grateful for feedback on the relevance of the topic, general content, style of presentation, as well as all other comments that will help further improve the quality of writing a collection of articles and the release of a book covering the topic of the practical side of using XML documents in e-commerce. More detailed information about the practical side of using electronic documents can be found on the author’s website www.eDocs.al.ru It is also planned to post source texts and examples on the author’s website.</p> <p>ORDER PROBLEM SOLUTIONS ON DELPHI <br>Delphi is the second most important programming language that students are most often introduced to during their studies. This is the beginning of learning object-oriented programming. As a student, I concluded that there is no easier way to master a language than to write a calculator in it. Even if you implement a basic function for adding two numbers, this will shed light on a lot.</p> <p>CodeGaear, Delphi 7, Lazarus are different compilers, programs that will transfer the code you write to the machine, converting it into zeroes and ones. These are all programs for creating programs, not separate programming languages. These compilers use the Object Pascal programming language, which is the basis of the Delphi language, which is similar in syntax to regular Pascal, but functionally differs significantly. <br></p> <h2>What is programming language syntax?</h2> <p>This is the format for writing various operators. For example, a “for” loop in Pascal has the following format: “for n:=1 to k do”, etc.</p><p>In the C++ programming language, the same cycle is written slightly differently: for (n = 1; n We write a calculator</p><p>This will give you an understanding of how objects interact with program code, what “variables” are, and how mathematical functions work. Any programming will be a calculation in any case. A game is also a program that constantly calculates something, works with numbers and numerical functions. Programming is inseparable from mathematics.</p> <p>We will use the Lazarus development environment for writing. Its functionality is not as rich as, say, CodeGear, but it is freely available and intended for learning.</p><p>Opening the development environment, we see a form and a toolbar. Here's the form.</p> <p><img src='https://i0.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-24.jpg' width="100%" loading=lazy loading=lazy></p><p>Here is the elements panel.</p><p>The first thing we will do is add the three elements we need to implement the function of adding two numbers. You need: “Tedit” in the amount of three pieces and “TButton”. In the picture below they are shown in the panel with arrows. We click on them once, and then once on the form, and they appear on it.</p><p>These are text input fields and a regular button. You encounter these elements when using almost any Windows program. Take a look.</p><p><img src='https://i1.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-27.jpg' width="100%" loading=lazy loading=lazy><br></p> <p>Now let's clear these inscriptions. Click the View tab. And click on “Object Inspector.” A window like this will appear.</p><p><img src='https://i2.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-28.jpg' width="100%" loading=lazy loading=lazy></p><p>We click once on our “Button” element on the form and change the “Caption” value in the inspector window to any other. For example, the word “Ok”. Press Enter. We see on the form how the element has changed its name.</p><p>We will do the same with Edits, but we will not rename them, but will make them without any content. Select them one by one and clear the Text value in the inspector. Don't forget to press Enter.</p><p><img src='https://i1.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-29.jpg' width="100%" loading=lazy loading=lazy></p><p>As a result, our form looks like this.</p><p><img src='https://i1.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-30.jpg' width="100%" loading=lazy loading=lazy><br></p> <p>Now, for our calculator to work, we need to write the necessary program code for the procedure of our button. Double-click on the Button element and open the source code editor.</p><p><img src='https://i2.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-31.jpg' width="100%" loading=lazy loading=lazy></p><p>Do you see? Procedure Button1Click. This is a procedure that is responsible for what will happen when we press the button once. And the following should happen: the program needs to display in the third Edit the sum of the numbers entered in the first two fields. We write code.</p><p><img src='https://i1.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-32.jpg' width="100%" loading=lazy loading=lazy></p><p>We need to write such simple 5 lines of code. Comments and explanations are visible in the picture above. After that, click this button.</p> <p>Our project will be compiled. It will be compiled into a program. We enter the numbers in the first two fields, click on the button and get the value of the sum.</p><p><img src='https://i2.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-34-2.jpg' width="100%" loading=lazy loading=lazy></p> <h2>Conclusion</h2> <p>You can click the “File” button, then “Save All”, select a folder to save and you will have a full-fledged program that can be launched from the desktop. Now try to figure out on your own what needs to be rewritten in this code so that the program divides two numbers rather than adding them. Hint: You need to change the data type. The video below shows a similar example, but in Delphi 7, not Lazarus.</p><p><span class="6qR5tjJKK3g"></span></p> <script>document.write("<img style='display:none;' src='//counter.yadro.ru/hit;artfast_after?t44.1;r"+ escape(document.referrer)+((typeof(screen)=="undefined")?"": ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth? screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";h"+escape(document.title.substring(0,150))+ ";"+Math.random()+ "border='0' width='1' height='1' loading=lazy loading=lazy>");</script> <div class="moduletable"> <div class="custom"> <div id="yandex_rtb_R-A-173290-2"></div> </div> </div> <div class="moduletable"> <div class="dopzagl">Thematic materials:</div> <div class="row-fluid dopmat"> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/useful/kak-udalit-poisk-rambler-iz-gugla-kak-ubrat-startovuyu-stranicu-rambler-iz.html"> <img src="/uploads/8295cfee06811d00501287dbaac4a82a.jpg" alt="How to remove the Rambler start page from the Opera, Mozilla, Google Chrome browser" title="How to remove the Rambler start page from the Opera, Mozilla, Google Chrome browser" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/useful/kak-udalit-poisk-rambler-iz-gugla-kak-ubrat-startovuyu-stranicu-rambler-iz.html">How to remove the Rambler start page from the Opera, Mozilla, Google Chrome browser</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/windows-xp/statistika-po-socialnym-setyam-osobennosti-auditorii-socialnoi-seti.html"> <img src="/uploads/895d4e8a8b7ea78715409adfdd8f856d.jpg" alt="Features of the audience of the social network “Odnoklassniki” Age of those registered on social networks" title="Features of the audience of the social network “Odnoklassniki” Age of those registered on social networks" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/windows-xp/statistika-po-socialnym-setyam-osobennosti-auditorii-socialnoi-seti.html">Features of the audience of the social network “Odnoklassniki” Age of those registered on social networks</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/windows-xp/kak-izmenit-razmer-saidbara-ruchnoi-metod-i-redaktura-pri-pomoshchi-visual.html"> <img src="/uploads/dce6bcdc8bc0ea67ec2dfa05317999a8.jpg" alt="Changing WordPress Theme Width Sidebar Resizing Plugin" title="Changing WordPress Theme Width Sidebar Resizing Plugin" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/windows-xp/kak-izmenit-razmer-saidbara-ruchnoi-metod-i-redaktura-pri-pomoshchi-visual.html">Changing WordPress Theme Width Sidebar Resizing Plugin</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/printers/kak-rasshirit-temu-v-wordpress-kak-sozdat-polnuyu-shirinu-stranicy-na-wordpress.html"> <img src="/uploads/32c38c02713c57b40acc153723045c64.jpg" alt="How to Create a Full Width Page in WordPress" title="How to Create a Full Width Page in WordPress" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/printers/kak-rasshirit-temu-v-wordpress-kak-sozdat-polnuyu-shirinu-stranicy-na-wordpress.html">How to Create a Full Width Page in WordPress</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/security-and-protection/socseti-pod-mikroskopom-ili-v-poiskah-celevoi-auditorii.html"> <img src="/uploads/7b777a5f316cd4835a89eefc16e6593f.jpg" alt="Features of the VKontakte audience What are the audiences of different social networks" title="Features of the VKontakte audience What are the audiences of different social networks" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/security-and-protection/socseti-pod-mikroskopom-ili-v-poiskah-celevoi-auditorii.html">Features of the VKontakte audience What are the audiences of different social networks</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/windows-10/pluso-knopki-socialnyh-setei-kak-bystro-ustanovit-i-nastroit.html"> <img src="/uploads/3e55604d783686bfd187123bada10430.jpg" alt="How to quickly install and configure" title="How to quickly install and configure" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/windows-10/pluso-knopki-socialnyh-setei-kak-bystro-ustanovit-i-nastroit.html">How to quickly install and configure</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/programs/chto-luchshe-yandeks-ili-google-kakoi-poiskovik-vybrat-yandeks-ili.html"> <img src="/uploads/d082a7c8ad43cc84a36dfd2480806dda.jpg" alt="Which search engine to choose - Yandex or Google?" title="Which search engine to choose - Yandex or Google?" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/programs/chto-luchshe-yandeks-ili-google-kakoi-poiskovik-vybrat-yandeks-ili.html">Which search engine to choose - Yandex or Google?</a> </header> </div> <div class="span3"> <div class="image-feat"> <a href="https://3dgosha.ru/en/windows-7/kak-sozdat-gruppu-v-facebook-dlya-biznesa-instrukciya-kak-raskrutit.html"> <img src="/uploads/bce54c02f2ac0c31f0cb9a2b4e3f0636.jpg" alt="How to promote a group on Facebook?" title="How to promote a group on Facebook?" / loading=lazy loading=lazy> </a> </div> <header> <a href="https://3dgosha.ru/en/windows-7/kak-sozdat-gruppu-v-facebook-dlya-biznesa-instrukciya-kak-raskrutit.html">How to promote a group on Facebook?</a> </header> </div> </div> </div> </p> <div class="article-info muted"> <div class="modified"> <span class="icon-calendar"></span> Updated: 02/18/2023</div> <div class="hits"> <span class="icon-eye-open"></span> 103583 </div> </div> <div class="proofreader_prompt">If you notice an error, select a piece of text and press Ctrl+Enter</div> </div> <div class="sharecont img-rounded"> <span class="lin">SHARE:</span> <div class="share42init" data-url="" data-title=""></div> <script type="text/javascript" src="/templates/vyborovednew/js/share42/share42.js"></script> </div> </div> <div class="span3 mainfreim"> <div class="moduletable"> <h3>Site headings</h3> <ul class="nav menu"> <li class="item"><a href="https://3dgosha.ru/en/category/windows-10/" title="Windows 10">Windows 10</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/internet-wifi/" title="Internet, Wi-fi">Internet, Wi-fi</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/useful/" title="Useful">Useful</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/windows-7/" title="Windows 7">Windows 7</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/errors/" title="Errors">Errors</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/iron/" title="Iron">Iron</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/windows-xp/" title="Windows XP">Windows XP</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/printers/" title="Printers">Printers</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/windows-8/" title="Windows 8">Windows 8</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/programs/" title="Programs">Programs</a></li> <li class="item"><a href="https://3dgosha.ru/en/category/treatment-of-viruses/" title="Treatment of viruses">Treatment of viruses</a></li> </ul> </div> <div class="moduletableadvert"> <div class="customadvert"> <center> </center> </div> </div> </div> </div> </div> </div> </div> <div class="container-fluid"> <div class="row-fluid"> <div class="span12 bottomarrow"> <div class="topbegr futerdesktop"> <div class="container"> <div class="row-fluid"> <div class="span4 center"><a href="https://3dgosha.ru/en/" ><img src="/uploads/logo.svg?1" alt="Computers and modern gadgets" / loading=lazy loading=lazy></a> </div> <div class="span8"> <div class="span12 menufuter center"> <ul class="nav menu"> <li><a class="str" href="https://3dgosha.ru/en/">home</a></li> <li><a class="but" href="">About the magazine</a></li> <li><a class="otz" href="https://3dgosha.ru/en/feedback.html">Contacts</a></li> <li><a class="vopr" href="">Advertising</a></li> </ul> <div class="span12 futercopir center"><div style="float:left; width:90%;">Copyright © 2023 3dgosha.ru - Computers and modern gadgets</div> <div style="float:right; width:10%;"> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <script type="text/javascript"> (function($) { $.lockfixed(".moduletableadvert",{ offset: { top: 10, bottom: 10} }); } )(jQuery); </script> <div id="proofreader_container" class="proofreader_container" style="display:none;"></div></body> </html>