Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Extensible Markup Language [XML] is a
markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable.The design goals of XML focus on simplicity, generality, and usability across the Internet.It is a textual data format with strong support via Unicode for different human languages. Although the design of XML focuses on documents, the language is widely used for the representation of arbitrary data structures such as those used in web services.
XML is an inherently
hierarchical data format, and the most natural way to represent it is with a tree.To perform any operations like parsing, searching, modifying an XML file we use a modulexml.etree.ElementTree.It has two classes.ElementTree represents the whole XML document as a tree which helps while
performing the operations. Element represents a single node in this tree.Reading and writing from the whole document are done on the ElementTree level.Interactions with a single XML element and its sub-elements are done on the Element level.
Bàn luận
Đặc tính | Sự mô tả Can be accessed using elementname.tag. |
Nhãn | Chuỗi xác định loại dữ liệu mà phần tử đại diện. Có thể truy cập bằng ElementName.tag. Can be accesses by elementname.attrib. |
Số lượng thuộc tính | Được lưu trữ dưới dạng từ điển python.can có thể truy cập bởi ElementName.Attrib. |
Chuỗi văn bản | Chuỗi thông tin liên quan đến phần tử. |
Chuỗi trẻ em | Thông tin chuỗi yếu tố con tùy chọn. |
Yếu tố trẻ em
We can parse XML data from a string or an XML document.Considering xml.etree.ElementTree as ET.
1. ET.parse[‘Filename’].getroot[] -ET.parse[‘fname’]-creates a tree and then we extract the root by .getroot[].
2. ET.fromstring[stringname] -To create a root from an XML data string.
Example 1:
XML document:
Số lượng phần tử trẻ em đến một gốc cụ thể.
Phân tích cú pháp: Chúng ta có thể phân tích dữ liệu XML từ một chuỗi hoặc tài liệu XML.Considing XML.ETREE.ElementTree là et.1. Et.parse [‘fileName,]. Et.FromString [StringName] -để tạo một gốc từ chuỗi dữ liệu XML.example 1: & nbsp; tài liệu XML: & nbsp;
XML
6
=
Mã Python: & nbsp; & nbsp;
?>
4 ?>
5
?>
8=
4
?>
5
version
70=
2
version
81>
4>
55__2844
Các
version
97version
98>
5=
00=
01=
02