• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# XML Overview
2
3
4Extensible Markup Language (XML) is a versatile markup language used to describe data, offering a flexible way to transport and store information, particularly in web applications. Unlike predefined markup languages like HTML, XML allows users to define their own tags, making it highly adaptable for various applications.
5
6
7An XML document is composed of the following components:
8
9
10- Elements: tag pairs that can enclose text, attributes, or other elements.
11
12- Attributes: additional details about the elements.
13
14- Content: data or nested elements within an element.
15
16
17XML supports the use of XML Schema Definition (XSD) or Document Type Definition (DTD) to define the structure of documents. This allows you to create custom validation rules to ensure that XML documents adhere to their intended format.
18
19
20Additional features of XML include namespaces, entity references, comments, and processing instructions, which enhance its flexibility and applicability across different data scenarios.
21
22
23The ArkTS common library provides essential XML functionalities such as [XML generation](xml-generation.md), [XML parsing](xml-parsing.md), and [XML conversion](xml-conversion.md).
24
25The following is a simple XML example with explanations. For details about more XML interfaces and their usage, see [@ohos.xml](../reference/apis-arkts/js-apis-xml.md).
26
27```XML
28<?xml version="1.0" encoding="utf-8"?> <!--Declaration-- >
29<!--Processing instruction-->
30<?xml-stylesheet type="text/css" href="style.css"?>
31<!--Element, attribute, and attribute value-->
32<note importance="high">
33    <title>Happy</title>
34    <!--Entity reference-->
35    <todo>&amp;</todo>
36    <!--Namespace declaration and URI -->
37    <h:table xmlns:h="http://www.w3.org/TR/html4/">
38        <h:tr>
39            <h:td>Apples</h:td>
40            <h:td>Bananas</h:td>
41        </h:tr>
42    </h:table>
43</note>
44```
45