XML Basics - Markup and structure of XML documents. "8


The book contains tips, algorithms and ready-made examples of programs from various areas: encryption, file and network operations, XML, ASP.NET, interaction with MS Office and Internet Explorer etc. The syntax of the C# language, issues of debugging and profiling applications, as well as problems that arise when switching from other programming languages ​​to the C# language are described. Examples of the most commonly used regular expressions are considered. A separate chapter is devoted to working with equipment.
The archive contains the book itself and a CD with the source code.

The manual is intended for programmers beginning and continuing to study Java SE, JEE and other technologies. Its first part covers the basics of the Java language and the concepts of object-oriented programming. The second part covers aspects of using Java class libraries, including files, collections, network and multi-threaded applications, and interaction with XML. The third part provides the basics of distributed programming information systems using servlets, JSP and developer's own tags. The fourth part gives the basics practical application design patterns.
At the end of each chapter, test questions are given on the material in the chapter and tasks to complete.
The appendices provide additional material related to the use of UML, SQL, Ant, XML, as well as brief descriptions of the popular technologies Log4J, JUnit, JPA and Hibernate.

Description of the book Open XML is short and accessible:
This book contains detailed review three main markup languages ​​of the Open XML standard. The book is intended for readers familiar with XML or HTML. Architects and software developers building document-centric solutions will learn how to build those solutions on the Open XML platform.

This book will be useful both for those new to markup languages ​​and for experts in the field who are not familiar with Open XML.

Description of the book Advanced Applications and Structures in Xml Processing: Label Streams, Semantics Utilization and Data Query Technologies:
Applications and Structures in XML Processing: Label Streams, Semantics Utilization and Data Query Technologies reflects the significant research results and latest findings of scholars’ worldwide, working to explore and expand the role of XML. This collection represents an understanding of XML processing technologies in connection with both advanced applications and the latest XML processing technologies that is of primary importance. It provides the opportunity to understand topics in detail and discover XML research at a comprehensive level.

Description of the book XML: Web Application Development:
The book offers a complete description of the XML language in conjunction with the XSLT and XPath languages ​​presented in the first part. The second part of the book contains practical guide on the application of the material presented in the first part of the book. In addition to XML, issues that arise when building real Web applications are addressed, namely, passing HTTP request parameters to the server, designing forms, presenting data using cascading style sheets, and processing user actions using JavaScript.

Part I. XML from A to Z

  • XML language
  • XSLT language
  • XPath language
  • Complex example
  • Necessary additions

Part II. Practical development of web applications

  • Tools for creating a Web application
  • Cascading Style Sheets
  • Data processing methodology
  • Data presentation

Description of the book Python & XML:
If you are a Python programmer who wants to incorporate XML into your skill set, this is the book for you. Python has attracted a wide variety of developers, who use it either as glue to connect critical programming tasks together, or as a complete cross-platform application development language. Yet, because it is object-oriented and has powerful text manipulation abilities, Python is an ideal language for manipulating XML.

Python & XML gives you a solid foundation for using these two languages ​​together. Loaded with practical examples, this new volume highlights common application tasks, so that you can learn by doing. The book starts with the basics then quickly progresses to complex topics, like transforming XML with XSLT, querying XML with XPath, and working with XML dialects and validation. It also explores the more advanced issues: using Python with SOAP and distributed web services, and using Python to create scalable streams between distributed applications (like databases and web servers).

The book provides effective practical applications, while referencing many of the tools involved in XML processing and Python, and highlights cross-platform issues along with tasks relevant to enterprise computing. You will find ample coverage of XML flow analysis and details on ways in which you can transport XML through your network.

Whether you are using Python as an application language, or as an administrative or middleware scripting language, you are sure to benefit from this book. If you want to use Python to manipulate XML, this is your guide.

Description of the book XML Bible:
The emergence of XML is having an enormous impact on Web development, and scaling the learning curve of this new technology is a priority for many developers. The XML Bible offers a superb introduction to the subject and the groundwork to understand XML"s future developments.

Author Elliotte Rusty Harold uses a patient, step-by-step discussion that clearly points out the potential of XML without boring his readership with tons of SGML spec-speak. Harold opens quickly with a "Hello World" example to get the reader coding early, and follows that with a simple but powerful example of XML"s data management benefits—presenting baseball statistics. Once you"ve coded your first XML documents, you" ll be hooked on the technology and motivated to learn about the more sophisticated topics.

Style sheet languages ​​are covered comprehensively to illustrate the presentation possibilities and pitfalls. An unusually long list of real-life XML applications also shows how XML is already being used, and there is in-depth coverage of the Resource Description Framework, Channel Definition Format, and Vector Markup Language. The book wraps up with a section that helps you design your own XML application from scratch.

Description of the book XSLT. Collection of recipes:
The XSLT (Extensible Stylesheet Language Transformation) language has become the main tool for processing XML documents, but many developers still have not fully mastered it and therefore believe that it is easier to modify existing code than to write new code from scratch. In version 2.0, many problems have been resolved, but there are a number of new features that still need to be explored. In addition, it is not yet sufficiently supported.

The second edition of this book contains hundreds of solutions to problems that programmers regularly encounter. Options are given for both versions of XSLT. The recipes range from string manipulation and math to advanced topics like extending XSLT, testing and debugging style sheets, and creating SVG graphics. Each recipe justifies the choice of solution and explains the technique used. For many problems, alternative solutions are provided with comments regarding usability and performance.

Offering recipes for a variety of skill levels, this book is the ideal companion for the programmer who loves to learn by example. Whether you're new to XSLT or are already familiar with the language and want a set of ready-made recipes for solving complex problems, here you'll find a variety of ways to use XSLT.

Description of the book Learning XML:
This edition focuses on Extensible XML Markup Language, a promising and powerful tool that provides a flexible way to create self-documenting documents and sharing both format and data on the Internet. The history, current state and tasks of XML, fundamental issues are considered. For beginning developers, the basics of XML document creation techniques and the concepts of XML elements, attributes, entities, and namespaces are covered. Addressed to professionals difficult questions— transformations, document modeling, fine-tuning templates, XML programming, using links and cascading style sheets.

The book shows with examples how to effectively use XML by formatting and transforming XML documents so that they can be processed by browsers, databases, and so on. The material is accompanied by links to real projects. The appendices describe Internet resources, books, and standards related to XML. A glossary is included in the book.

Description of the book XML. Directory:
The XML Reference is a source of information for developers in the rapidly evolving world of XML. Once readers understand the core XML standard, they can quickly grasp the intricacies of DTDs, namespaces, XML document correctness, and Unicode support.

One of the most unexpected directions in the development of XML was its active adoption for working with structured documents: electronic and mathematical tables, statistical and financial reports and software files.

An overview of key technologies used primarily for narrative XML documents such as web pages, books, and articles will help you gain a working knowledge of XSLT, XPath, XLink, XPointer, CSS, and XSL-FO. Surely many will be interested in using XML for intensive data processing.

Several chapters are devoted to the utilities and APIs needed to write XML processing programs such as SAX - simple API for XML, and DOM - the document object model of the W3C consortium.

The book also includes material that forms the basis of any O"Reilly reference book. These chapters provide detailed syntax rules (accompanied by examples) of the main XML technologies, including DTD, XPath, XSLT, SAX and DOM. This reference describes the rules that Authors of all XML documents should adhere to this, both web designers creating animations using SMIL and C++ programmers using SOAP to serialize objects to a remote database.

You've probably heard of XML and know many reasons why it should be used in your organization. But what exactly is XML? This article explains what XML is and how it works.

In this article

Markups, markup and tags

To understand XML, it's useful to remember how you can tag data. Documents were created by people over many centuries, and throughout that time people made notes on them. For example, teachers often mark up student work to indicate the need to move paragraphs, make a sentence clearer, correct spelling errors, etc. Marking a document can help determine the structure, meaning, and appearance of information. If you've ever used revisions in Microsoft Office Word, then you're familiar with the computerized markup form.

In the world information technologies the term "marking" has become the term "marking". Markup uses codes called tags (or sometimes tokens) to define the structure visual design and - in the case of XML - the meaning of the data.

The HTML text of this article is a good example of the use of computer markup. If in Microsoft Internet Explorer right click this page and select command View HTML code, you will see readable text and HTML tags like

AND

. In HTML and XML documents, tags are easy to recognize because they are enclosed in angle brackets. In the source text of this article, HTML tags perform many functions, such as defining the beginning and end of each paragraph (

...

) and the location of the drawings.

Features of XML

HTML and XML documents contain data enclosed in tags, but that's where the similarities between the two languages ​​end. In the HTML format, tags determine the design of the data - the location of headings, the beginning of a paragraph, etc. In the XML format, tags determine the structure and meaning of the data - what it is.

By describing the structure and meaning of data, it becomes possible to reuse it in several ways. For example, if you have a block of sales data in which each element is clearly defined, you can load only the necessary elements into the sales report and transfer the other data to the accounting database. In other words, you can use one system to generate and tag data in XML format, and then process that data in any other systems, regardless of the client platform or operating system. This compatibility makes XML the basis of one of the most popular data exchange technologies.

Please note the following when working:

    HTML cannot be used instead of XML. However, XML data can be enclosed in HTML tags and displayed on web pages.

    HTML capabilities are limited to a predefined set of tags that are common to all users.

    XML rules allow you to create any tags required to describe the data and its structure. Let's say you need to store and share information about pets. To do this, you can create the following XML code:

    Izzy Siamese 6 yes no Izz138bod Colin Wilcox

As you can see, the XML tags make it clear what data you are viewing. For example, it's clear that the data is about a cat, and you can easily determine its name, age, etc. Because you can create tags that define almost any data structure, XML is extensible.

But don't confuse the tags in this example with the tags in the HTML file. For example, if the above XML text is pasted into an HTML file and opened in a browser, the results will look like this:

Izzy Siamese 6 yes no Izz138bod Colin Wilcox

The web browser will ignore the XML tags and display only the data.

Well formed data

You've probably heard someone in IT talk about a "well-formed" XML file. A well-formed XML file must follow very strict rules. If it doesn't follow these rules, the XML doesn't work. For example, in the previous example, each opening tag has a corresponding closing tag, so this example follows one of the rules of a well-formed XML file. If you remove a tag from a file and try to open it in one of the Office programs, an error message will appear and it will be impossible to use such a file.

You don't need to know the rules for creating a well-formed XML file (although they are not difficult to understand), but remember that only well-formed XML data can be used in other applications and systems. If the XML file does not open, it is probably malformed.

XML is platform independent, which means that any program designed to use XML can read and process XML data, regardless of hardware or operating system. For example, if you apply the right XML tags, you can use a desktop program to open and process data received from the mainframe. And, regardless of who created the XML data, the data can be manipulated in a variety of Office applications. Due to its compatibility, XML has become one of the most popular technologies for exchanging data between databases and user computers.

In addition to well-formed tagged data, XML systems typically use two additional components: schemas and transformations. The following sections describe how they work.

Scheme

Don't be intimidated by the term "scheme". A schema is simply an XML file that contains rules for the contents of the XML data file. Schema files usually have the extension XSD, while XML data files use the XML extension.

Schemas allow programs to validate data. They form the structure of the data and ensure that it is understandable to the creator and other people. For example, if the user enters invalid data, such as text in a date field, the program may prompt the user to correct it. If the data in an XML file matches the rules in the schema, you can use any XML-enabled program to read, interpret, and process it. For example, as shown in the image below, Excel can validate data for compliance with the CAT scheme.

Circuits can be complex, and this article cannot explain how to create them. (Also, there are likely IT people in your organization who know how to do this.) However, it is useful to know what the diagrams look like. The following diagram defines the rules for a set of tags ... :

Don't worry if the example isn't clear. Just pay attention to the following:

    The string elements in the example schema are called declarations. If additional information about the animal was required, such as its color or special characteristics, the IT department would add appropriate declarations to the diagram. The XML system can be modified as business needs evolve.

    Declarations are a powerful means of manipulating data structure. For example, an ad means that tags such as And , must follow in the above order. Ads can also validate the types of user input. For example, the above circuit requires a positive integer input for the cat's age and Boolean values ​​(TRUE or FALSE) for the ALTERED and DECLAWED tags.

    If the data in an XML file follows the rules of the schema, then the data is said to be valid. The process of verifying that an XML data file conforms to schema rules is called (logically enough) validation. The big advantage of using schemas is that they can prevent data corruption. Schemas also make it easier to find corrupt data because XML file processing stops when a problem occurs.

Transformations

As discussed above, XML also allows for efficient use and reuse of data. The mechanism for reusing data is called an XSLT transformation (or simply transformation).

You (or your IT department) can also use transformations to exchange data between back-end systems, such as databases. Let's assume that database A stores sales data in a table that is useful to the sales department. Database B stores income and expense data in a table specifically designed for accounting. Database B can use a transformation to take data from Database A and put it into the appropriate tables.

The combination of the data file, schema, and transformation forms the basic XML system. The following figure shows the operation of such systems. The data file is checked against the schema rules and then passed in any suitable way for transformation. In this case, the transformation places the data in a table on a web page.

The following example shows a transformation that loads data into a table on a web page. The point of the example is not to explain how to create transforms, but to show one of the forms they can take.

Name Breed Age Altered Declawed License Owner

This example shows what the text of one type of transformation might look like, but remember that you may be limited to a clear description of what you need from the data, and that description can be done in your native language. For example, you might go to the IT department and say that they need to print sales data for specific regions for the last two years, and that the information should look like this and that. The department can then write (or modify) a transformation to fulfill your request.

Microsoft and a growing number of other companies are creating transforms for a variety of purposes, making XML even more convenient to use. In the future, it will likely be possible to download a conversion that suits your needs with little or no additional customization. This means that over time, using XML will become less and less expensive.

XML in the Microsoft Office system

Professional editions of Office provide enhanced XML support. Beginning with the 2007 Microsoft Office System, Microsoft Office uses XML-based file formats such as DOCX, XLSX, and PPTX. Because XML stores data in a text format rather than a proprietary binary format, clients can define their own schemas and use your data in a variety of ways without having to pay royalties. For more information about the new formats, see Open XML Formats and File Name Extensions. Below are other benefits.

This is all great, but what if you have XML data without a schema? This depends on which Office program you are using. For example, when opening an XML file without a schema in Excel application it assumes that the schema exists and allows you to load the data into an XML table. You can use XML lists and tables to sort, filter, and calculate data.

Enable XML features in Office

By default, the Developer tab is not visible. It must be added to the ribbon to use XML commands in Office.

As I said in the about section, this technology is a sophistication that not everyone needs, but having mastered it, you can safely call yourself a real professional not only in creating a website, but also Web programming, Firstly.

But this path will be extremely thorny. And this site contains only part of the information about this technology. In particular, the possibilities for creating, managing and parsing XML document V PHP.

And at the heart of communication with XML document lies DOM standard (Document Object Model ), which is the basis for working with documents XML. This standard is present not only in PHP, but also in all languages ​​that understand this format ( Java, C++, JavaScript and others).

And here with the standard DOM We are about to meet in this category. We will consider this standard in PHP. Although DOM standard, that’s why it’s called a “standard” because the operating principles remain the same when moving to other languages, so there are no problems with XML documents It won't work in other languages.

Now let’s begin to study this complex, but undoubtedly important technology.

After reading articles on XML basics, you will learn:

1) Why is it needed? XML.

2) Structure XML document.

3) How to do RSS feed Online.

4) How to do affiliate-shop on the base XML-fida.

5) How to do XML string parser.


XML Language - A Practical Introduction. Part 2

Detailed description of Databet88.

XML (Extensible Markup Language) is a new SGML-derived document markup language that allows you to structure information of various types using an arbitrary set of instructions. Developers of Internet applications trying to use in practice new technology, may be interested in specific questions related to the problems of creating, processing XML documents, and displaying them on the client side. This article gives a brief idea of ​​what an XML document is and why it is needed, and illustrates with practical examples some simple, but so far, unfortunately, little described mechanisms for processing it.

What is XML

Today, XML can be used in any applications that need structured information - from complex geographic information systems with gigantic volumes of transmitted information to ordinary “single-computer” programs that use this language to describe service information. Taking a closer look at the information world around us, we can identify many tasks related to the creation and processing of structured information, for which XML can be used:

  • First of all, this technology may be useful for developers of complex information systems, with a large number of applications connected by information flows of various structures. In this case, XML documents serve as a universal format for exchanging information between separate components big program.
  • XML is the base standard for a new resource description language, RDF, which simplifies many of the problems on the Web associated with finding the right information and maintaining control over content. network resources, creation of electronic libraries, etc.
  • The XML language allows you to describe data of any type and is used to represent specialized information, such as chemical, mathematical, physical formulas, medical prescriptions, musical notations, etc. This means that XML can serve as a powerful complement to HTML for distributing "non-standard" information on the Web. Perhaps in the very near future, XML will completely replace HTML, at least the first attempts to integrate these two languages ​​are already being made (XHTML specification).
  • XML documents can be used as an intermediate data format in three-tier systems. Typically, the interaction pattern between application and database servers depends on the specific DBMS and the SQL dialect used to access the data. If the query results are presented in some universal text format, then the DBMS link, as such, will become “transparent” to the application. In addition, today the W3C has proposed a specification for a new database query language, XQL, which in the future may become an alternative to SQL.
  • The information contained in XML documents can be modified, transmitted to the client machine, and updated piecemeal. The XLink and Xpointer specifications being developed will make it possible to refer to individual elements of a document, taking into account their nesting and attribute values.
  • Using style sheets (XSL) allows you to provide output-device-independent display of XML documents.
  • XML can be used in common applications to store and process structured data in a single format.

A superficial description of the language can be found in the first two chapters. Let me remind you only in general terms that an XML document is an ordinary text file, in which, using special markers, data elements are created, the sequence and nesting of which determines the structure of the document and its content. The main advantage of XML documents is that, with relatively in a simple way creation and processing (plain text can be edited by any test processor and processed by standard XML parsers), they allow the creation of structured information that is well “understood” by computers.

How to create an XML document?

To create an XML document in the simplest case, you will not need anything other than a regular text editor (according to many Web designers, the best tool for creating Web pages). Here's an example of a small XML document used in place of a regular notebook:

Important business meeting We need to meet with Ivan Ivanovich after calling him on the phone 123-12-12 ... Call home 124-13-13

When creating your own markup language, you can come up with any element names (almost any, since the list of allowed characters is limited and given in the XML specification), corresponding to the context of their use. Our example shows only one of many ways to create a diary structure. This is the flexibility and extensibility of XML-derived languages ​​- they are created by the developer “on the fly”, according to his ideas about the structure of the document, and can then be used universal programs viewing on a par with any other XML-derived languages, because all the information necessary for parsing is contained within the document.

When creating a new format, it is necessary to take into account the fact that there cannot be documents “written in XML” in principle - in any case, the authors of the document for its markup use a language based on the XML standard (the so-called XML-derived) language, but not XML itself. Therefore, when saving the created file, you can select for it some extension suitable for the name (for example, noteML).

XML can be used by you to create documents of a specific type and structure necessary for specific application. However, if the scope of the language turns out to be wide enough and it begins to be of interest to a large number of developers, then its specification may well be submitted for consideration to the W3C and, after agreement by all interested parties, approved by the consortium as an official recommendation.

It should be noted that the process of creating a new specification is very long and complex. Any document proposed by the W3C goes through several stages before becoming a standard. First, wishes and recommendations coming from various companies participating in its development are formalized in the form of a note taken into account, a kind of protocol of intent. The information contained in such documents is intended for discussion by consortium members only and no guarantee is given that these comments will subsequently become recommendations.

The next stage of document promotion is a working version of the specification, which is compiled and subsequently modified by a specially created working group (Working Group), which includes representatives of companies interested in the idea. All changes made to this document are necessarily published on the consortium server www.w3.org and until the working version becomes a recommendation, it can only serve as a “guiding star” for developers, with which the company can check its plans, but not should be used in software development.

In the event that the parties have agreed on all the main issues and more significant changes are made to the document, the working version becomes a Proposed Recommendation and after voting by the members working group may already become an Official W3C Recommendation, which in status corresponds to the standard in the WWW.

XML generators

XML documents can serve as an intermediate format for transferring information from one application to another (for example, as the result of a database query), so their content is sometimes generated and processed automatically by programs. It is not always necessary to create an XML document manually.

Let, for example, our task is to create a format for storing registration data of some events occurring in the system (log file). In the simplest case, we can limit ourselves to recording successful and failed requests to our resources - such a document should contain information about the time of the event, its result (success/error), IP address of the request source, resource URI and result code.

Our XML document might look like this:

195.151.62.18 GET /misc/ 200 195.209.248.12 GET /soft.htm 200

The structure of the document is quite simple - root at in this case is the log element, each event that occurs is recorded in the event element and is described using its attributes (date - time and result - event type) and internal elements (method - access method, ip-from - source address, url-to - requested resource, response - response code). This document can be generated, for example, by a system request authentication module, and used by a registration data processing program (log viewer).

What is DTD?

So, we created an XML document and made sure that the set of tags used allows us to carry out any manipulation with our information. In this case, in order to establish the rules of our new language, i.e. a list of valid elements, their possible contents and attributes, we must create DTD definitions (at the time of writing, the specification of data schemas for XML documents has not yet been approved and so far DTDs are the only standard way to describe the grammar).

Save this file as log.dtd and include a new line in the XML document:

Now, when processing a document, the verifying XML analyzer will check the order of defining elements and their attributes with the way it is specified in our DTD notations and, in case of violation of the internal structure (which determines the “semantics” of the document), issue an error message.

What are Namespaces?

As mentioned earlier, the beauty of using XML lies in the ability to come up with your own tags, the names of which would most fully correspond to their purpose. But people's imagination and vocabulary are not limitless, so there is absolutely no guarantee that the element names you give will not be used by someone else. As long as your application only processes native XML documents, there won't be any problems. But it is quite possible that the same document will contain information for several processors at the same time. In this case, the names of some elements or their attributes may be the same, causing either an error in the XML parser or an incorrect presentation of the document. For example, in our case, the event element could easily be used to record other events and be processed by another application.

To correct this situation, we must define unique names for elements and their attributes by “adding” some universal, non-repeating prefix to their regular names. The Namespaces mechanism is used for this (the Namespaces specification was officially approved by the W3C in January 1999 and is now part of the XML standard). According to this specification, to define the "scope" of a tag (in fact, this term, widely used in conventional programming languages, is not applicable in XML, because there is no set as such on which the "scope" could be built within the structured XML document ) it is necessary to define a unique attribute that describes the name of the element, by which the document analyzer can determine which group of names it belongs to (Namespace identifiers can be used to describe the unique names of both elements and their attributes). In our last example it could be done like this:

195.151.62.18

GET

/misc/

200

195.209.248.12

GET

/soft.htm

200

The uniqueness of the name attribute is ensured by the use of some universal resource identifiers (for example, URI or ISBN) as its value.

Full information on using Namespace can be found in the official specification of this standard. In the future, to simplify the examples, we will skip Namespace - descriptions.

Tools

Processing XML Documents

The main limiting factor in the promotion of XML technology on the Web today is the lack of full support for this format by all browser manufacturers - programs most often used on the client side. A way out of this situation can be an option in which the server side processes XML documents. Using any existing XML analyzer, you can generate necessary information already on the server and send the client a normal HTML document. However, this method is, of course, less flexible and allows you to use XML technology only for storing structured information, but not for dynamically changing it on the client side.

In August 1997, RFC 2376 approved the MIME types for XML resources: text/xml and application/xml. Therefore, XML documents can be transmitted over HTTP and displayed by the viewer in the same way as regular HTML pages. To do this, you need to slightly change the Web server configuration (in Apache - add the line "text/xml xml ddt" to the mime.types file), and on the client side have a browser that supports style sheets or JavaScript. Today, these browsers include Microsoft Internet Explorer 5, the first browser to support the XML 1.0 specification and XSL stylesheets; Amaya browser, offered by the consortium specifically for testing purposes (http://www.w3.org/Amaya/User/BinDist.html) and supports almost all developed W3C standards. XML support is also planned for future versions of Netscape Navigator.

Document Object Model DOM

One of the most powerful interfaces for accessing the content of XML documents is the Document Object Model - DOM.

The object model of XML documents is a representation of its internal structure in the form of a collection of specific objects. For convenience, these objects are organized into some kind of tree-like data structure - each element of the document can be assigned to a separate branch, and all its contents, in the form of a set of nested elements, comments, CDATA sections, etc. is represented in this structure by subtrees. Because Since any well-formed XML document must have a main element defined, all content can be considered as subtrees of this main element, then called the root of the document tree. For the following XML document fragment:

text text

The element tree looks like this:

Fig.1 Tree of elements

Object representation of document structure is not something new for developers. Scripting has long used an object-oriented approach to access the content of an HTML page; elements of an HTML document accessible to Java Script or VBScript could be created, modified, and viewed using appropriate objects. But their list and set of methods is constantly changing and depends on the type of browser and language version. In order to provide an interface to access the contents of a structured document, independent of a specific programming language and document type, the specification of the DOM Level 1 object model was developed and officially approved within the W3 consortium.

DOM is a specification for universal platform- and software-independent access to the contents of documents and is simply a kind of API for their handlers. DOM is a standard way of constructing an object model of any HTML or XML document, with the help of which you can search for the necessary fragments, create, delete and modify its elements.

To describe interfaces for accessing the content of XML documents, the DOM specification uses the platform-independent language IDL and to use them they must be “translated” into a specific programming language. However, this is done by the creators of the analyzers themselves; we may not know anything about the way interfaces are implemented - from the developers’ point of view application programs The DOM looks like a collection of objects with certain methods and properties. In the next section, we'll take a quick look at the Microsoft Internet Explorer 5 object model, accessible from Java Script and VBScript scripts.

First steps

Let us now examine the first example in more detail. Let us recall its text.


< tutorial >
< title >"Notes on XSL"
< author >Leonov Igor Vasilievich

The first line informs the browser that the file has XML format. The version attribute is required. The encoding attribute is optional, but if you have Russian letters in your text, then you need to insert this attribute, otherwise the XML file simply will not be processed - you will receive an error message.

The following lines are the body of the XML file. It consists of elements that together form a tree structure. Elements are identified by tags and can be nested within each other.

Elements can have attributes whose values ​​can also be processed according to the template.

There is always one element at the top level of an XML file. That is, a file like


< tutorial >
< title >"Notes on XSL"
< author >Leonov Igor Vasilievich

< tutorial >
< title >"Introduction to CSP"
< author >Leonov Igor Vasilievich

will not be processed by the browser. To convert to a valid XML file, you need to add top-level element tags, for example


< knowledgeDatabase >
< tutorial >
< title >"Notes on XSL"
< author >Leonov Igor Vasilievich

< tutorial >
< title >"Introduction to CSP"
< author >Leonov Igor Vasilievich

< /knowledgeDatabase >

Note that tag names are case sensitive. You can read more about this in any book on XML - elements and attributes are given quite a lot of attention in these books.

Let's now move on to the transformation template - the XSL file. The job of an XSL file is to transform the tree of the XML file into another tree that, for example, will conform to the HTML format and can be displayed on the browser screen, taking into account formatting, font choices, etc.

In order for the browser to perform the necessary transformation, you need to specify a link to the XSL file in the XML file


Let's now look at the text of the XSL file

< xsl:stylesheet version =" 1.0" xmlns:xsl =" http://www.w3.org/TR/WD-xsl">
< xsl:template match =" /">
< p >< strong >< xsl:value-of select =" //title""/>
< p >< xsl:value-of select =" //author"/>

The first line of the file contains the xsl:stylesheet element tag. The element's attributes are the version number and namespace reference. These xsl:stylesheet element attributes are required. In our case, the namespace is all the names of elements and their attributes that can be used in the XSL file. For XSL files, namespace reference is standard.

Note that an XSL file is a type of XML file. It does not contain user data, but its format is the same. The file contains a top-level element xsl:stylesheet , followed by a tree of transformation rules.

In this document, we will not explain in detail what each element in the XSL file means. We will bring various examples and show the result in each example. The reader will be able to independently correlate the various elements of the XSL file and the transformations initiated by these elements of the source XML file with user information.

In the future, we will provide the texts of XML and XSL files in black and white. You can always open the real file and see everything in color. If necessary, comment out the link to the XSL file. The comment syntax is as follows - . You cannot insert the symbols -- into the comment text.

In the first example, we looked at how the xsl:value-of element can be used to display the contents of the element (text enclosed between tags) in HTML format. Now we'll see how we can use the same element to display the value of an element's attribute.

Consider the following XML file ex02-1.xml







In this file, information is stored not in the contents of the elements, but in the form of attribute values. The ex02-1.xsl file looks like




.
, .



Note the element attribute reference syntax - //dog /@ name. The element name and attribute name are separated by a pair of "/@" characters. Otherwise the syntax is the same as for referencing the element's content.

The result looks like this:

Dog: Ball. 18 kg, red with black tan.

Let us now turn our attention to the next point. We didn't use the tutorial element in any way in the XSL file. In fact, the full path could have been used. Let's rewrite our XML file, increasing the depth of the tree (ex02-2.xml)















2024 gtavrl.ru.