How to create xml file delphi. Using the XML Document Object Model. Using XML DOM in Borland Delphi

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

In this article, we will look at the XML Document Object Model (DOM) and Microsoft's implementation of the 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 core objects: XMLDOMDocument, XMLDOMNodeList, XMLDOMNode, XMLDOMNamedNodeMap, and XMLDOMParseError. Each of these objects (except XMLDOMParseError) contains properties and methods that allow you to get information about the object, manipulate the object's values ​​and structure, and navigate the structure of an XML document.

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

Using XML DOM in Borland Delphi

In order to use 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 (Version 2.0) library, which is usually located in the Windows \ System \ MSXML.DLL file

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

XML DOM device

The Document Object Model represents an XML document in a tree structure of branches. Programming interfaces XML DOMs 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. Most XML documents contain branches of type element, attribute, and text. Attributes are a special kind of branch and are not child branches. Special methods provided by XML DOM objects are used to manipulate attributes.

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 in a specific context, and the TransformNode method supports using XSL to perform transformations.

Test XML Document

As an example XML document, let's take a music CD-ROM directory, 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

We are now ready to start looking at the XML DOM object model, starting 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 that specifies the URL of the loaded document. 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, use the LoadXML method to load the document.

The Async property is used to control how the document is loaded (synchronous or asynchronous). 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 loads synchronously, and then you have to check the value of the ReadyState property to see if the document has loaded or not. You can also create an event handler for the OnReadyStateChange event that will take 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’); // // This is where the code that manipulates // the XML document and its branches // XMLDoc: = Nil; end;

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

Error handling

Of particular interest are properties related to document processing upon loading. For example, the ParseError property returns an XMLDOMParseError object containing information about an error that occurred while processing the document.

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 find out what information is returned in case of an error, change the following directory entry:

Empire burlesque Bob dylan USA Columbia 10.90 1985

removing the closing element on 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 property values ​​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 execute our application. As a result, we get the following information about the error.</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 cause of its occurrence.</p> <p>Now we will restore the closing element <TITLE>in our document and continue our discussion of the 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 the document tree, you can either get the root element and then iterate over 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 contents 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 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 as defined in the XML Schema or Document Type Definition (DTD) and returns a branch with that identifier.</p> <p>The GetElementByTagName method requires a string with a specific element (tag) and returns all branches with this element. Here's 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>The 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 a branch of an XML document, you can use the properties of the XMLDOMNode object (Table 1).</p> <p>To access the data stored in a branch, it is common to use either the NodeValue property (available for attributes, text branches, comments, processing instructions, and CDATA sections), or 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 items.</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, the ParentNode property (XMLDOMNode type) is used to access the parent branch, the child branches are accessed through the ChildNodes properties (XMLDOMNodeList type), FirstChild and LastChild (XMLDOMNode type), etc. The OwnerDocument property returns an XMLDOMDocument object that identifies the XML document itself. The properties listed above make it easy to navigate the document tree.</p> <p>Now let's loop 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 SelectNodes of the XMLDOMNode object 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 define XSL templates for branch searches.</p> <p>Let's look at the process of using the SelectNodes method to fetch all branches that have a CD branch and a PRICE sub-branch:</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 come back to discussing XSL templates a bit 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 record about 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 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 value of an element through the Text property;</li> <li>… Repeat for all elements.</li> </ul></li> <li>Adding a new branch to the 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 place in the tree, you need to use the InsertBefore method.</p> <h2>Branch set - XMLDOMNodeList object</h2> <p>The XMLNodeList object contains a list of branches, which can be built using the SelectNodes or GetElementsByTagName methods, and also obtained from the ChildNodes property.</p> <p>We have already discussed the use of this object in the example provided in the section "Navigating the document tree". Here are some theoretical comments.</p> <p>The number of branches in the list can be obtained as the value of the Length property. The branches are indexed from 0 to Length-1, and each individual branch is accessible through the corresponding indexed item in the Item array.</p> <p>Navigating through the 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 top 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>Create and save documents</h2> <p>So, we've covered how you can add branches and elements to existing XML documents. Now let's create an XML document on the fly. First of all, remember 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 the rest of the elements (which we already covered in the section "Manipulating child branches"):</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 building the XML document, save it to 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 an XML document in a new XMLDOMDocument object. In this case, the document is fully processed and, as a result, its structure and syntax are checked. Here's how to save a document to 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 the 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 SelectNodes method of the XMLDOMNode object, we mentioned that it provides a more flexible way to access document branches. The flexibility is that you can specify an XSL template as the criteria for selecting branches. Such templates provide a powerful mechanism for finding information in XML documents. For example, to get a list of all the music CD-ROM titles in our directory, you can run the following query:</p><p>To find out which artists' discs are released in the United States, the request is formed as follows:</p><p>Nodes: = Root.SelectNodes (‘CD / ARTIST’);</p><p>Here's how to find the first drive in a 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's disks, 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 disks made 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 publication. To intrigue readers and encourage further research, I will give just one small example of the possible use of XSL. Let's say we need to convert our directory to a regular HTML table. Using the traditional methods, we must iterate over all the branches of the tree and for each received element form the corresponding tags <TD>…</TD>.</p> <p>Using XSL, we simply create a template (or stylesheet) that specifies what and how to transform. Then we overlay this template on our catalog - and we're done: this is the text of the XSL template that transforms the catalog into a table (Listing 2).</p> <p>The code to overlay an 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 at present this language is actively used for transformation between various XML documents, as well as for formatting documents.</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 cover all Microsoft XML DOM objects and provide examples of their use in one article. Here we have just touched on the basic issues of using XML DOM in applications. Table 3 shows all the objects implemented in the Microsoft XML DOM.</p> <p>ComputerPress 12 "2000</p> <p>Recently, much attention has been paid to the construction of e-business systems, or as they are also called - B2B (business to business). Considering the recommendations for the construction of exchange streaming systems of the coordinating body of Internet technologies - WWW Consortium: the emphasis is on XML technologies and the construction of systems for the exchange of XML documents.</p> <p>The advantage of using XML in e-business is the high efficiency of B2B systems at low costs for 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 the presentation of information in the form of XML documents allows different companies involved in e-business to produce software independent of each other.</p> <p>In all systems, the exchange, as a rule, is built according to the same scheme, using HTTP requests. The SSL protocol is used as the 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, which issues an HTTP request in POST mode, on the other hand, there is a WEB server on the side of which the request is processed and a response is issued. The information exchange uses XML documents.</p> <p>One of the most efficient implementation options is to use an existing XML parser that supports the DOM model. Such a parser is a distribution package of Win'98 or an integral part 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) - presents encapsulated data and methods into a single entity and a way to access them through a system of interfaces. Using Delphi tools, 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 the interface system. The description of interfaces is carried out by the interface definition language (IDL), which can be carried out automatically by means of the environment.</p> <p>Delphi tools are used to import from a COM server <i>msxml.dll</i>, the files for the description of the IDL interface and the file for the binary description of the 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 framework generates a Pascal COM server description file - MSXML_TLB.pas</p> <p>The MSXML_TLB.pas file describes all the interfaces, constants, and coclasses of the COM server.</p> <p>To access objects of a COM element, you need in the directive <b>USES</b> add the name of the library description file (MSXML_TLB.pas). Below is a simple program using the standard DOM parser msxml.dll, which loads an XML document and displays it in a 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 the soclass 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>// create an instance of the DOMDocument object;</span> Doc: = coDoc.Create; <span>// call the Load method of an instance of the DOMDocument object;</span> Doc.load ("data.xml"); <span>// access the xml property of the DOMDocument instance;</span> Memo1.Text: = Doc.xml; <b>end;</b> <b>end.</b> <h2>DOM Concept - Document Object Model</h2> <p>Each XML document is represented as a set of multiple objects (classes), with the help of which it is possible to access individual elements (object fields). DOM - the interface describes access both to simple objects of the DOMString or CharacterData type, and to parts or individual elements of an XML document: DOMFragmentElement, DOMNode, DOMElement.</p> <p>Following are the most important properties and methods of XMLDOMDocument, XMLDOMNode, XMLDOMNodeList objects. It should be noted that the methods and functions of DOM objects presented below (Document Object Model) are used by the Microsoft XML parser msxml.dll and are somewhat broader than the model approved by the W3C DOM 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, 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 XML document to file</td> </tr><tr><td valign="top" width="39%"><b>abort</b> </td> <td valign="top" width="61%">Interruption of the process of loading and processing the document.</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 within a document</td> </tr><tr><td valign="top" width="39%"><b>getElementsByTagName (tagname)</b> </td> <td valign="top" width="61%">Returns a reference to the 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%">Finding an item 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">XMLDOMNode object that implements the basic DOM interface <b>Node</b>, is intended for manipulating a separate node of the document tree. Its properties and methods allow you to get 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%">Specifies 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%">Gets a list of the attributes of the current node as an XMLDOMNamedNodeMap collection.</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 XMLDOMNodeList.</td> </tr><tr><td valign="top" width="35%"><b>firstChild, lastChild</b> </td> <td valign="top" width="65%">Returns the first / last child</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 containing the current node.</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 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 refChild.</td> </tr><tr><td valign="top" width="35%"><b>cloneNode (deep)</b> </td> <td valign="top" width="65%">Creates a copy of the current item.</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 the 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%">Replacing the oldChild object of the current list of child objects with newChild. Deleting oldChild object</td> </tr><tr><td valign="top" width="35%"><b>selectNodes (patternString) selectSingleNode (patternString)</b> </td> <td valign="top" width="65%">Returns an XMLDOMNodeList object selected by 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 representing the result of the processing. The parameter is a reference to the DOMDocument object that contains the XSL statements.</td> </tr></tbody></table><br><h2>Using XML in Business.</h2> <p>For a clearer picture, an explanation is needed, and 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 the pr-I, an efficiently proven system of information transfer based on existing WEB servers over HTTP protocols is used.</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 the side of which the request is processed and a response is issued. XML documents are used as an exchange.</p> <p>For example, in a simple corporate ERP system, an accounting program (ACS Accounting), it is necessary to form a request for an invoice and send it to a branch that has a warehouse (ACS Warehouse). AWP A similar problem statement when creating a B2B system, when Enterprise A requests the availability of products (makes an order for the purchase) from Supplier B.</p> <p>Enterprise A and its program act as a client. The warehouse is served by Supplier B, who has a warehouse complex with a database on a SQL server. The exchange is carried out through the corporate WEB server of the Supplier V.</p> <p>Below is the following typical exchange algorithm:</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 Provider B. As a URI, the resource identifier of the processing application is used. 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> by passing the body of the XML document as a parameter. <br>Process B is launched by the WEB server and is processed either as an ASP page, CGI (ISAPI) - application or JAVA server (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>According to 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>Further, depending on the situation on the client side, either a new http request is formed, or the session ends.</li> </ol><h2>A few words about the organization of document flow.</h2> <p>The general rule for developing a system for exchanging XML documents is:</p><ul><li><b>At first</b>- development of a flow chart of electronic documents and their structure;</li><li><b>Secondly</b>- development of tables of process functions (subprocesses), i.e. what function each process will implement with respect to what XML document.</li> </ul><p>Each XML document, like an HTML document, must consist of a message header (information enclosed by tags) and a message body (for a request, this information is framed with tags to respond to a request). In order for an XML document to be well formed, it is necessary to frame its two component parts "Title" and "Request" with tags, for example. The type of a typical document is presented below:</p> <p>The header (Figure 4), in contrast to an HTML document, must contain various kinds of service information, including information about the type of the transmitted document 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 should be the same for all types of documents.</p> <p>For the Process started by the server, it is preferable (but not necessary) to build the processing algorithm 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 side</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 a Delphi text portion of a message xml header generating program.</p> <b>procedure</b> TThread1.HeaderCreate (Sender: Tobject); <b>var</b> <span>// class declaration, needed 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>// create DOM document</span> Doc: = coDoc.Create; Doc.Set_async (false); <span>// initial initiation of the DOM document</span> Doc.LoadXML (" <Header/>"); <span>// create DOMElement (tag<<b>Sender</b>>) </span> Node: = Doc.createElement ("Sender"); <span>// create a text node " <b>Typhoon LLC</b>" </span> txt: = Doc.createTextNode ("Typhoon LLC"); <span>// assignment to node<<b>Sender</b>> value</span> <span>// text node " <b>Typhoon LLC</b>" </span> Node.appendChild (txt); <span>// add element<<b>Sender</b>> to the document root 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 the 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>// create 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 done once. The variable declaration is located in the section describing global variables, and not in the local procedure, as it was demonstrated for clarity in this example (that is, one global variable of the DomDocument type per one program module).</p> <p>The result of the work of the above program will be the created header, applied 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 transferring information in the form of XML documents is that it is possible to form a message using independent table structures in the DBMS both on the receiving and on the transmitted side. Using our example, suppose it is required to transfer information about the invoices of Enterprise A, from the 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, Qulity, Price, HZ_cod <b>FROM</b> Goods <b>WHERE</b> InvoiceNum =: num <span>//: num is a parameter that specifies the invoice number.</span> <p>Below is a part of the program that generates the body of the xml document:</p> <b>procedure</b> TThread1.DataBodyCreate (Sender: Tobject); <b>var</b> <span>// declaration of the class and the XMLDomDocument object</span>// coDoc: CoDomDocument; <span>// must be global for the whole module.</span>// Doc: DomDocument; <span>// declare 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 query // queryA - query A with general information about the invoice // queryB - query B information about the goods described in the invoice (see text)</span> <b>begin</b> Query.Close; <span>// see the text "request A"</span> Query.Text: = queryA; <span>// execute the request</span> Query.ExecSQL; Query.Open; <span>// get 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>// add an element to the root</span> r.appendChild (Node2); <span>// add an item to</span> Node2. appendChild (Node); <span>// create DOMElement (tag)</span> Node3: = Doc.createElement ("Depurture"); <span>// add an item to</span> Node. appendChild (Node3); <span>// call to the "Depurture" field of the request</span> str: = Query.FieldByName ("Depurture"). AsString; <span>// create text node = field value</span><span>// assign a value to the node</span> <span>// text node, variable str</span> Node.appendChild (txt); <span>// similar operations for the tag <Destination>, <DataSend>, // <DataDepurture>, <Currency> // <DestinationCompany>(DB field "Consignee")</span> Node: = Doc.createElement ("Destination"); <span>// the name of the database field may not be the same as 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 XML interface, // like ORACLE 8i or Ms SQL 2000</span> Node.appendChild (txt); ... <span>// generating a request for a specification for goods</span> <span>// close the request for access</span> Query.Close; <span>// see in the text "request B", info. About goods</span> Query.Text: = queryВ; <span>// assignment of parameter values</span> Query.Params.AsInteger: = InvoiceNumber; <span>// execute the request</span> Query2.ExecSQL; <span>// open access to request data</span> Query.Open; <span>// create DOMElement (tag)</span> Node3: = Doc.createElement ("Imems"); <span>// add an item to</span> Node. appendChild (Node3); <span>// loop through all lines of the query</span> <b>while</b> <b>not</b> Eof.Query <b>do</b> begin Node4: = Doc.createElement ("Imem"); <span>// add an item to</span> Node3.appendChild (Node4); <span>// formation of 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 an XML document is generated:</p> <table width="100%"><tbody><tr><td align="middle"><br><img src='https://i0.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, - Server url varAsync, - asynchronous / synchronous communication mode = true bstrUser, - username for authentication bstrPassword) - password <h2>Creating the server side of document processing</h2> <p>As noted earlier, processing an HTTP request can be handled by either CGI applications or Java servlets. The variant of writing ASP-pages is also possible. But in this case, data transfer is possible only by the "GET" method through the query string. However, handling an HTTP request for ASP pages is more efficient than a CGI application. However, in my opinion, it does not matter how to process it, but it is more important to solve the question - how to build a processing program, and not by what means.</p> <p>If from the previous chapter we examined the options for forming 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 an xml document:</p> <b>procedure</b> Tthread1.DataParser (Sender: Tobject); <b>var</b> <span>// declare DOMElement objects</span> r, FNode: IXMLDOMElement; Str, Filename: String; parm: String; <span>// soclass declaration and</span> CoDocXML, CoDocXSL, CoDocResult: CoDomDocument; <span>// XMLDomDocument object</span> XMLDoc, XSLDoc, ResultDoc: DomDocument; <span>// HttpStr: String; - a global variable containing the HTTP request string</span> <b>Begin</b> XMLDoc: = coDocXML.Create; XMLDoc.LoadXML (HttpStr); <span>// get the address of the root element</span> r: = Doc.Get_documentElement; <span>// get the value of the element</span> FNode: = r.SelectSingleNode ("// TypeDocument"); <span>// get the value of the attribute id = "Order"</span> FileName: = FNode.GetAttibute ("id"); <span>// and forming the file name Order.xsl</span> FileName: = FileName + ". Xsl"; <span>// create XSLDoc document</span> XSLDoc: = coDocXSL.Create; XSLDoc.LoadXML (FileName); <span>// create XMLDoc document</span> ResultDoc: = coDocResult.Create; <span>// set synchronous processing mode</span> ResultDoc.Set_async (false); <span>// set parse check</span> ResultDoc.validateOnParse: = true; <span>// parsing XMLDoc using XSL template</span> XMLDoc.transformNodeToObject (XSLDoc, ResultDoc); <span>// the Str variable is assigned a text value</span> <span>// of the resulting document.</span> Str: = ResultDoc.text; <span>// find an element</span> FNode: = r.SelectSingleNode ("// InvoiceNumber"); <span>// and get the value of the element</span> parm: = FNode.text; <span>// close the request for access</span> Query.Close; Query.Text: = Str; <span>// assignment of parameter value</span> Query.Params.AsString: = parm; <span>// execute the request</span> Query.ExecSQL; <b>end;</b> <p>The whole highlight of the parsing is the use of an XSL template, which is individually generated for each type of document. The result of parsing is a SQL query string. Subsequently, the execution of 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 also that you get some kind of data flexibility, and you get complete independence of the algorithm from the program code. Below is the text of the XSL template 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 formal in nature, since after parsing, the resulting XML document must formally contain at least one node. The ResultDoc.text method assigns the text value of the ResultDoc obtained during parsing of the XML document. In this case, the value is everything that is framed by a pair of tags and, i.e. the SQL query we have generated.</p> <p>Another feature of writing a program should be noted the possibility of using the SQL parameter <b>: num.</b> Using the parameter simplifies the text of the xsl template. The definition of the value of the corresponding elements of the nodes of the XML document is determined initially by the selection by the name of the corresponding node, for example:</p><h2>XSL at a glance</h2> <p>The abbreviation XSL comes from eXtensible Stylesheet Language - a style sheet formatting language (XML data). As you can see from the header, eXtensible Stylesheet Language (XSL) is used to format XML data. By definition, the W3C XSL consists of two parts:</p> <ul><li>XSLT - XSL Transformation. The language used to transform or format (transform) XML documents. Thus, with the help of XSLT, we can get different cuts of a set of data and forms of data presentation.</li><li>Formatting elements. These elements include all the typographic elements of the data, after processing them with XSL. Used only for generating HTML pages.</li> </ul><p>With the help of 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 have transformed XML data in the form of a SQL query. The classic use of XSL is usually formatting data in the form of HTML pages or, more rarely, in the form of RTF files.</p> <p>XSL file describes a template, according to which the transformation of XML data will be performed. 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>A directive indicating the use of matching templates for the select attribute = "template name"</td> </tr><tr><td>xsl: attribute</td> <td>creates an attribute tree and adds it to the output element, parameter name = "attribute name", namespace is the namespace URI (namespace prefix)</td> </tr><tr><td>xsl: call-template</td> <td>calls a template, attribute name = "URI to template"</td> </tr><tr><td>xsl: choose <br>xsl: when <br>xsl: otherwise</td> <td>selection by condition xsl: when expr = "evaluation of expression on 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 inserts a document fragment into a 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 of the node list, the select attribute specifies the list of nodes</td> </tr><tr><td>xsl: if</td> <td>condition check, set by the test attribute as an expression</td> </tr><tr><td>xsl: include</td> <td>includes external template, attribute href = "URI reference"</td> </tr><tr><td>xsl: output</td> <td>specifies the output, the method attribute can be "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 = "name of the instruction process"</td> </tr><tr><td>xsl: sort</td> <td>sorts set of 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-templates 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 = "an indication of the node to which the template is applied"</td> </tr><tr><td>xsl: text</td> <td>generates text to the output stream, attribute disable-output-escaping = "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, attribute select = "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 parameter to template, attribute name = "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 the standard XML parser <i>msxml.dll</i> is not the only tool for parsing and creating XML documents. For example, to create XML documents effectively use the components <b>TPageProduser</b> and <b>TableProduser</b>... But, this article only emphasizes the breadth and applicability of the DOM model in practice.</p> <p>The author will be very grateful for your feedback on the relevance of the topic, general content, presentation style, as well as all other comments that will help to 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 on the practical side of the use of electronic documents can be found on the author's website www.eDocs.al.ru It is also planned to place the source texts and examples on the author's site.</p> <p>Welcome! This blog is about the Internet and computers, or rather it was dedicated to them.</p> <p>Probably, it is immediately obvious that no new articles have appeared on the site for many years. Yes, that's the fate of most blogs. This project was once an ambitious undertaking, and the author, like many others who wrote at the time, had ambitious plans to become one of the best Russian bloggers. Well, if you look now, then of those blogs that were created simultaneously with mine, most have already disappeared into eternity. And I just didn't have enough time to blog. So yes, it is not being updated anymore. Although once we with this site won the competition "Blog of Runet 2011".</p> <p>I even had an idea to delete all this, but then I revised the old materials, and realized that they can still be useful to readers. Yes, some articles are outdated (if I have enough strength, they will receive appropriate notes), but the site, for example, can be useful for beginners - here you can read about the basic concepts of the Internet, learn how to configure the Internet, Windows, or even decide to switch to Linux. So look at the rubrics and choose the one that's right for you.</p> <p>And yet, I hope this is more than just a blog, but a real guide to the Internet. The site can be viewed in the directory mode, where all available articles are structured by category. 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 savings and cheap shopping. Poles are considered one of the most economical 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 an ordinary Internet user in Russia?</p> <p>Modern android phones are more than phones. You get used to the set of installed programs, the history of your calls and text messages, the collection of photos, and much more. But time passes, and the device that suits you completely begins to slow down, glitch, or simply loses its presentable appearance due to chips on the case or scratches on the screen. The question arises of choosing a new phone and changing the android phone. And if we now bypass the question of choice, then "moving" to a new phone remains a serious problem - we absolutely do not want to start all the data from scratch. This is what we are going to talk about today.</p> <p>Most of the readers of this blog, most likely, have never encountered version control systems and will not come across any in the near future. It's a pity. This extremely convenient invention is widely used by programmers, but, in my opinion, it could 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 interesting for all readers.</p> <p>If you have thought about how to watch movies on the network from your TV and go online, 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, therefore, recently the Google corporation demonstrated an absolutely stunning device, which immediately became a sensation. We're talking about the Chromecast media streamer (Chromcast), a more advanced and affordable version of last year's disastrous Nexus Q.</p> <p>The Chromcast Dongle, which is less than 2 inches in size, connects to your TV's HDMI port and lets you enjoy 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 device of the android system memory, the problems that may arise due to its lack and how to solve them. Not so long ago, I myself was faced with the fact that my android phone began to regularly give out messages about insufficient memory when trying to install an 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 with an additional memory card. However, there was a problem, and I had to tinker a lot before I found the right solution, which did not require root access or a full restoration of the phone to the factory state.</p> <p>ORDER A SOLUTION TO DELPHI <br>Delphi is the second most important programming language that students are most often introduced to in the learning process. This is the beginning of learning about object-oriented programming. As a student, I came to the conclusion that there is no easier method to learn a language than to write a calculator in it. Even if you implement a rudimentary function for adding two numbers, it 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 to ones 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 ordinary Pascal, but functionally differs significantly. <br></p> <h2>What is the syntax of a programming language?</h2> <p>This is the format for writing various operators. For example, a Pascal for loop has the following format: for n: = 1 to k do, and so on.</p><p>In the C ++ programming language, the same loop is written a little 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 in any case be a computation. A game is also a program that constantly calculates something, works with numbers and numerical functions. Programming is inseparable from mathematics.</p> <p>Let's use the Lazarus development environment for writing. Its functionality is not as rich as, say, CodeGear, but it is freely available and is intended for training.</p><p>Opening the development environment, we see the form and the toolbox. Here is the form.</p> <p><img src='https://i1.wp.com/reshatel.org/wp-content/uploads/2018/09/Bez-imeni-24.jpg' width="100%" loading=lazy loading=lazy></p><p>Here is the toolbox.</p><p>The first thing we will do is add the three elements we need to implement the function for adding two numbers. We need: "Tedit" in the amount of three pieces and "TButton". In the picture below they are shown on 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 fields for input and a regular button. You come across these elements 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 labels. Click the "View" tab. And click on the item "Object Inspector. A window like this will appear.</p><p><img src='https://i1.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". We press Enter. We see on the form how the element has changed its name.</p><p>Let's do the same with Edit's, just don't rename them, but make them without any content. Select them in turn and clear the Text value in the inspector. Do not forget to press Enter.</p><p><img src='https://i2.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, you need to write the necessary program code for the procedure of our button. Click on the Button element twice and open the source 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>See? Procedure Button1Click. This is the procedure that is responsible for what happens when we click on the button once. And the following should happen: the program needs to display the sum of the numbers entered in the first two fields in the third Edit. We write the 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 can be seen in the picture above. After that, we press this button.</p> <p>Our project will be compiled. It will be compiled into a program. We enter numbers in the first two fields, click on the button and get the value of the sum.</p><p><img src='https://i0.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 for yourself what you need to rewrite in this code so that the program divides two numbers, and does not add. Hint: you need to change the data type. The video below shows a similar example, but in the Delphi 7 environment, not Lazarus.</p><p><span class="6qR5tjJKK3g"></span></p> <p>For many Delphi programmers, saving settings is associated with using <i>INI</i> files in their programs. The use of this method, in more or less serious projects, should be avoided, as it limits flexibility, which prevents further expansion of the program. It should be said that this approach is quite popular due to its ease of use and the presence of built-in tools in the development environment. <br><br>However, structured <i>XML</i> files. Their advantage is that the number of parameters may not be fixed. To understand this better, consider a specific example.</p><p>In the USearch program, when you click on an entry, a context menu appears, in which a list of items is displayed. These items are commands, which in turn are loaded from the settings file. In case 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 required, you will have to rewrite the code and re-compile it 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>Applying an approach using <i>XML</i> files, we will be able to load all section parameters dynamically. In addition, the configuration file will become more elegant, without redundant parameter numbering. However, the standard tools for working with <i>XML</i> Delphi has many disadvantages, so I recommend using the standard library <b>MSXML</b>... Usually it is included by default with the operating systems of the Windows family.</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 create an interface file with a list of all functions by importing it from the COM server. Many detailed articles have been written on how to import the interface, but I suggest you download the file <b>MSXML2_TLB.PAS</b> 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 MSXML2_TLB line 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 by the standard any <i>XML</i> the file must contain the root tag (in this case <i>config</i>), then we need to get it using the function <i>DocumentElement</i>... Then the content is displayed between the tags. <width></width>, which in turn are between the tags <size></size>... Thus, from the settings.xml file, our method will display the 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>Here the SelectSingleNode method is applied, which takes a string as a parameter</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> <div class="clr"></div> </article> <div class="block-layout-one"> <p class="title"><span>Read <strong>also</strong></span></p> <div class="row"> <div class="item grid_4"> <a href="https://bmwworkshop.ru/en/numerovannyi-spisok-oformlenie-spiskov-v-css-kak-v-html-izmenit/"><img src="/uploads/fe2fc95c51701e9e590213fcef29e67f.jpg" / loading=lazy loading=lazy></a> <div> <span class="btn-blue"><a href="https://bmwworkshop.ru/en/category/security/" class="btn-blue">Security</a></span> <h3><a href="https://bmwworkshop.ru/en/numerovannyi-spisok-oformlenie-spiskov-v-css-kak-v-html-izmenit/">Styling lists in CSS How to change the numbering style in html</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </div> <div class="item grid_4"> <a href="https://bmwworkshop.ru/en/invertirovanie-cvetov-stranicy-html-s-pomoshchyu-button-css-filtry/"><img src="/uploads/1ae6c1cd18f3b3f1895cea2424a35127.jpg" / loading=lazy loading=lazy></a> <div> <span class="btn-blue"><a href="https://bmwworkshop.ru/en/category/setting/" class="btn-blue">Customization</a></span> <h3><a href="https://bmwworkshop.ru/en/invertirovanie-cvetov-stranicy-html-s-pomoshchyu-button-css-filtry/">Inverting html page colors using button</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </div> <div class="item grid_4"> <a href="https://bmwworkshop.ru/en/obuchenie-programmirovaniyu-s-nulya-s-chego-nachat-izuchenie-v-domashnih-usloviyah/"><img src="/uploads/fdf6909fd57af089423d49c76793b26c.jpg" / loading=lazy loading=lazy></a> <div> <span class="btn-blue"><a href="https://bmwworkshop.ru/en/category/security/" class="btn-blue">Security</a></span> <h3><a href="https://bmwworkshop.ru/en/obuchenie-programmirovaniyu-s-nulya-s-chego-nachat-izuchenie-v-domashnih-usloviyah/">How to learn to program from scratch at home How to start programming</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </div> <div class="item grid_4"> <a href="https://bmwworkshop.ru/en/text-decoration-tolshchina-linii-razdelitelnaya-liniya-v-vide-volny-na-css/"><img src="/uploads/c1deb7f58d1b9c30e655ce590ae94929.jpg" / loading=lazy loading=lazy></a> <div> <span class="btn-blue"><a href="https://bmwworkshop.ru/en/category/security/" class="btn-blue">Security</a></span> <h3><a href="https://bmwworkshop.ru/en/text-decoration-tolshchina-linii-razdelitelnaya-liniya-v-vide-volny-na-css/">Dividing line in the form of a wave in css</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </div> </div> <div class="row"> </div> </div> </div> <aside id="sidebar" role="complementary"> <div class="widget subscribe-widget"> <h3 class="widget-title">Subscribe to our digest</h3> <div> <form action="/" class="frmAjx searchform subscribeform" method="post"> <input type="text" class="text" name="ch_elem[email]" data-placeholder="Email" value="Email" /> <input type="submit" value="Subscribe to" /> </form> </div> </div> <div class="widget"> <h3 class="widget-title">Latest articles</h3> <ul class="recent-posts"> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/border-radius-krossbrauzernyi-vybor-resheniya-gorizontalnyi-i-vertikalnyi/"><img src="/uploads/a0b6e2c5a80197abe4e30183e278425a.jpg" alt="Border radius cross-browser" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/border-radius-krossbrauzernyi-vybor-resheniya-gorizontalnyi-i-vertikalnyi/">Border radius cross-browser</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/tvc-pomoshch-detyam-6162-fond-podari-zhizn-i-tv-centr-sobirayut-sredstva/"><img src="/uploads/07b963b7b9588a5a1e1e0a21f8ffcf0b.jpg" alt="Fund"подари жизнь" и "тв центр" собирают средства на лечение вадима самкова" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/tvc-pomoshch-detyam-6162-fond-podari-zhizn-i-tv-centr-sobirayut-sredstva/">Gift of Life Foundation and TV Center raise funds for the treatment of Vadim Samkov</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/chem-preimushchestvo-internet-telefonii-preimushchestva-ip-telefonii/"><img src="/uploads/1b3208bf0bb2769c0d212ac542d9f829.jpg" alt="Advantages of IP telephony" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/chem-preimushchestvo-internet-telefonii-preimushchestva-ip-telefonii/">Advantages of IP telephony</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/radialnyi-gradient-css-radialnyi-gradient-kombinaciya-gradienta-i/"><img src="/uploads/3cd699bbb5ea3dc2cd32f17ce7cfd084.jpg" alt="Radial Gradient Gradient and Background Image Combination" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/radialnyi-gradient-css-radialnyi-gradient-kombinaciya-gradienta-i/">Radial Gradient Gradient and Background Image Combination</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/kak-dobavit-svoi-html-kod-vstavka-php-koda-v-html-kak-pravilno-eto-sdelat/"><img src="/uploads/ee7a65c73fb24348628d4b81e2b9ff1c.jpg" alt="How do I add my HTML?" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/kak-dobavit-svoi-html-kod-vstavka-php-koda-v-html-kak-pravilno-eto-sdelat/">How do I add my HTML?</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/ispolzovat-strukturu-tegov-h1-h2-h3-h4-kak-pravilno-ispolzovat/"><img src="/uploads/d8715414fba260f076181484b019bc4a.jpg" alt="How to use H1 and H2 headings correctly when optimizing texts" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/ispolzovat-strukturu-tegov-h1-h2-h3-h4-kak-pravilno-ispolzovat/">How to use H1 and H2 headings correctly when optimizing texts</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/oformlenie-dlya-ugolkov-i-ramok-na-css-svoistvo-border-radius-zakruglenie-ramok-v-css/"><img src="/uploads/93f27c0b813c4c47ce661f84fa6bb031.jpg" alt="Styling for corners and borders in CSS" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/oformlenie-dlya-ugolkov-i-ramok-na-css-svoistvo-border-radius-zakruglenie-ramok-v-css/">Styling for corners and borders in CSS</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/kak-udalit-avatariyu-programma-dlya-nakrutki-avatarii-kak/"><img src="/uploads/0c59e7a10ec560b4b7b6f888ad3ada24.jpg" alt="Program for cheating avatars How to refresh the page with clearing the cache" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/kak-udalit-avatariyu-programma-dlya-nakrutki-avatarii-kak/">Program for cheating avatars How to refresh the page with clearing the cache</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/css-blok-na-vsyu-vysotu-stranicy-blok-shirinoi-na-ves-ekran-monitora/"><img src="/uploads/a0e4293960d98a5489c17575382238ca.jpg" alt="Align the whole monitor screen to the center of the browser window" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/css-blok-na-vsyu-vysotu-stranicy-blok-shirinoi-na-ves-ekran-monitora/">Align the whole monitor screen to the center of the browser window</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> <li> <div class="image"> <a href="https://bmwworkshop.ru/en/excel-vydelenie-stroki-cvetom-po-usloviyu-kak-vydelit-stroki-v-excel-po/"><img src="/uploads/853952af503ade46e3e1b81f9048a420.jpg" alt="How to select rows in Excel by condition?" / loading=lazy loading=lazy></a> </div> <div class="text"> <h3><a href="https://bmwworkshop.ru/en/excel-vydelenie-stroki-cvetom-po-usloviyu-kak-vydelit-stroki-v-excel-po/">How to select rows in Excel by condition?</a></h3> <p class="date">2021-09-06 11:40:14</p> </div> </li> </ul> </div> <div class="widget"> <h3 class="widget-title">Search</h3> <form class="searchform" action="/ru/search/"> <input name="q" type="text" value="" placeholder="What are we looking for?"/> <input type="submit" value="Search"/> </form> </div> <div class="widget widget-banner"> <h3 class="widget-title">Advertising</h3> <div class="ad-banner-300x250"> </div> </div> </aside> </div> </section> <img src="/assets/news_tape.gif" width="1" height="1" / loading=lazy loading=lazy> <footer id="footer" role="contentinfo"> <div class="inner-wrapper"> <div class="widget"> <h3 class="widget-title">about the project</h3> <p> <p><a href="" target="_blank">about the project</a></p> <p><a href="" target="_blank">For advertisers</a></p> </p> </div> <div class="widget"> <h3 class="widget-title">Fast passage</h3> <ul class="widget-categories"> <li><a href="https://bmwworkshop.ru/en/category/security/">Security</a></li> <li><a href="https://bmwworkshop.ru/en/category/internet/">Internet</a></li> <li><a href="https://bmwworkshop.ru/en/category/contacts-sms/">Contacts, SMS</a></li> <li><a href="https://bmwworkshop.ru/en/category/multimedia/">Multimedia</a></li> <li><a href="https://bmwworkshop.ru/en/category/setting/">Customization</a></li> <li><a href="https://bmwworkshop.ru/en/category/sync/">Synchronization</a></li> </ul> </div> <div class="widget"> <h3 class="widget-title">we are in social networks</h3> <noindex> <ul class="recent-comments"> <li> <a target="_blank" href="https://facebook.com/">Facebook</a> </li> <li> <a target="_blank" href="">Rss</a> </li> </ul> </noindex> </div> <div class="widget"> <h3 class="widget-title">Contacts</h3> <ul class="recent-comments"> <li><a href="">Feedback form</a></li> </ul> </div> </div> <div id="copyright"> <div class="inner-wrapper"> <div class="row"> <div class="grid_6">2021 bmwworkshop.ru. All rights reserved.</div> </div> </div> </div> </footer> <div class="b-subscribe-facebook h"> <div class="b-subscribe-facebook-inner">Liked? <a href="https://facebook.com/">Like us on Facebook</a></div> </div> </div> <noindex> <script type="text/javascript" src="/js/build/jquery.v2.js"></script> <script type="text/javascript" src="/js/build/project.v28.js"></script> <script type="text/javascript"> //<![CDATA[ project.pseudoReady(); //]]> </script> <div class="b-counter-list"> <div class="b-counter"> </div> </div> </noindex> </body> </html>