Example of Uses of XML (explained And With Code)
Xml / / April 02, 2023
In this article we are going to explore 10 common uses of XML that have revolutionized the way we share information online. You'll discover how XML has become an essential tool for RSS feeds, document formats, vector graphics, and 10 examples explained and coded.
XML is an extensible markup language that allows you to create custom labels for data, making it easy to exchange information between different applications and operating systems. With XML, information can be structured in a clear and coherent way, allowing you to focus on content rather than format. XML frees you from the chains of format incompatibility and allows you to share your data with the world simply and efficiently.
10 examples of common uses of XML with code
- RSS: The RSS (Really Simple Syndication) format uses XML to distribute news and content from a website through syndication channels. RSS readers use XML to receive and display the latest news from the websites they follow.
Code:
1.0 UTF-8?>
https://www.ejemplode.com
https://www.ejemplode.com/microsoft-windows11
https://www.ejemplode.com/apple-iphones2023
In this example, an RSS feed is defined with the title "Technology News" and includes two "item" elements that represent recent news. Each "item" element contains information about the title, the link, the description and the date of publication of the news item.
This XML file can be used to distribute this news through different syndication channels, such as RSS readers or websites that aggregate content from various sources.
- XHTML: XHTML (Extensible HyperText Markup Language) is an extended version of the HTML language that uses XML for the definition of its syntax and allows greater flexibility in the definition of the elements and attributes.
Code:
This is a sample website created with XHTML. 1.0 UTF-8?>
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
" https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Welcome to my website
In this example, an XHTML document is defined that contains a header and a body. The header includes information about the title of the website and the character encoding used.
The body contains a level 1 header welcoming the user and a paragraph describing the website. Also included is a list with links to three different pages.
This XML file can be processed and displayed in a web browser that supports XHTML, such as Firefox or Google Chrome.
- svg: The SVG (Scalable Vector Graphics) format uses XML to represent scalable vector graphics in the web, allowing for higher resolution and image quality compared to other video formats. image.
Code:
1.0 UTF-8?>
In this example, a vector graphic is defined using SVG (Scalable Vector Graphics). The file starts with an XML declaration and an element which sets the size of the drawing area to 300 pixels wide by 200 pixels high.
inside element, two shapes are added: a blue rectangle with an (x, y) position of (50,50) and a width and height of 200 y 100 pixels, respectively, and a white circle with center (cx, cy) at (150,100) and radius 40 pixels. Also included is an item which shows the word "SVG" centered in the circle.
This XML file can be processed and displayed in a web browser that supports SVG, such as Firefox or Google Chrome.
- SOAP: SOAP (Simple Object Access Protocol) uses XML to enable communication between web applications over the Internet. SOAP defines a set of rules for creating XML messages that are sent and received over the network.
Code:
1.0 UTF-8?>
xmlns: xsi=" https://www.w3.org/2001/XMLSchema-instance"
xmlns: xsd=" https://www.w3.org/2001/XMLSchema">
In this example, a Simple Object Access Protocol (SOAP) message is defined that is used to exchange structured information between applications on a network.
The file starts with an XML declaration and an element which defines the SOAP namespace and the namespaces for XML Schema (xsi) and XML Data (xsd). inside element, an element is included containing authentication information, including username and password.
Also included is an item containing the content of the message, in this case a request to obtain user information using a user identifier. Elements are nested within custom namespaces for authentication and user information, respectively.
This XML file can be sent to a SOAP web service for processing and response.
- XSLT: The XSLT (Extensible Stylesheet Language Transformation) transformation language uses XML to transform XML documents into other formats, such as HTML or PDF.
Code:
1.0 UTF-8?>
Shopping list
In this example, an XSLT (Extensible Stylesheet Language Transformation) transformation is defined that is used to transform an XML document into another format, in this case HTML.
The file starts with an XML declaration and an element
In this example, an HTML page that displays a shopping list is created using the standard HTML elements, such as ,
and . inside element , an element is included- to create an unordered list and a loop
- for each with the value of the element's text content as the content of the HTML element.
- Atoms: the Atom format uses XML to provide a standard format for publishing web content, such as blogs and news sites.
Code:
1.0 utf-8?>
... more tickets...
In this example, an Atom file is defined that represents a news feed or blog. The file starts with an XML declaration and an element that defines the Atom namespace.
inside element This includes metadata such as the blog title, links to the blog's home page and to itself, the feed's unique identifier, and the most recent update date. Also included is an item containing information about the author of the blog.
inside element one or more elements are included, each of which represents a post or blog entry. Each contains metadata such as the title, links to the post, the unique identifier of the post, and the date updated.
Also included is an item A containing a summary of the content of the entry.
This XML file can be used to read blog content or to create a news feed.
- RDF: The Resource Description Framework (RDF) uses XML to provide a standardized way to describe resources on the web, such as websites and files multimedia.
Code:
1.0 UTF-8?>
xmlns: dc=" https://purl.org/dc/elements/1.1/"
xmlns: ex=" https://ejemplode.com/">
In this example, an RDF file is defined that describes information about two articles on a website. The file starts with an XML declaration and an element that defines the RDF namespace.
inside element, two elements are defined, one for each item. Each has an attribute rdf: about A that indicates the resource to which it refers (in this case, the URL of the article).
inside each, elements are included, , and, which represent the article title, author, date, and description, respectively. A custom element is also included A that represents the number of views the article has had.
This RDF file can be used to share information about articles on the web or to create a news feed.
- XBRL: The XBRL (Extensible Business Reporting Language) format uses XML for the presentation and exchange of financial and business reports online.
Code:
1.0 UTF-8?>
xmlns: iso4217=" https://www.xbrl.org/2003/iso4217"
xmlns: xsi=" https://www.w3.org/2001/XMLSchema-instance"
xmlns: link=" https://www.xbrl.org/2003/linkbase"
xmlns: xbrli=" https://www.xbrl.org/2003/instance"
xmlns: iccbba=" https://www.xbrl.org/2008/ICCBBA">
xlink: label="ReportingEntity">iccbba: ICCBBA
This example contains financial information for a company and is written in XBRL (eXtensible Business Reporting Language), a markup language used to standardize reporting financial.
The file begins with a header indicating the version and encoding of the document. The namespace is then defined, and elements are used to represent information about the reporting entity, period, and scenario.
Units of measure are also defined for numerical values and facts (facts) such as sales and net income are presented in the context of the current year.
- kml: The KML (Keyhole Markup Language) format uses XML for the representation of geospatial data and is commonly used in mapping and navigation applications.
Code:
1.0 UTF-8?>
This example represents a Keyhole Markup Language (KML) file that is used to describe geographic information in a structured format.
The file begins with a header indicating the version and encoding of the document, followed by the Document section that contains general information about the file, such as the name and the description.
Then, a Folder is defined that groups the Placemark elements that represent places on the map. Each Placemark contains information such as the name, description, and coordinates of the place represented by a Point element.
In this example, the Monument to the Revolution and the Azteca Stadium in Mexico City are represented.
- OpenDocument: The OpenDocument Format uses XML for the creation and editing of text documents, spreadsheets, and presentations, enabling interoperability between different software applications.
Code:
1.0 UTF-8?>
xmlns: office="urn: oasis: names: tc: opendocument: xmlns: office: 1.0"
xmlns: text="urn: oasis: names: tc: opendocument: xmlns: text: 1.0"
xmlns: table="urn: oasis: names: tc: opendocument: xmlns: table: 1.0">
This example represents an OpenDocument file that is used to create text documents, spreadsheets, and presentations.
The file begins with a header indicating the namespaces used in the document, followed by the office: body section containing the document content.
The office: text section is used to add text and the table: table section is used to add a table with three columns: Name, Age, and Profession. Each table row is defined with a table element: table-row and each cell with a table element: table-cell.
The file shows two rows with information from two different people.
Quoted APA: Del Moral, M. & Rodriguez, J. (s.f.). Example of Uses of XML (explained And With Code).Example of. Retrieved on March 31, 2023 from https://www.ejemplode.com/21-xml/5294-ejemplo_de_usos_del_xml_explicado_y_con_codigo.html