Net-informations.com
SiteMap  | About    

Python XML Processing

What is XML ?

XML stands for eXtensible Markup Language . The XML standard is a flexible way to create information formats and electronically share structured data via the public Internet, as well as via corporate networks.

XML Parser

The Document Object Model (DOM) defines a standard for accessing and manipulating documents. The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure.

XML parsing in Python

Python can parse xml documents in several ways. It has traditional dom and sax parsers. This chapter will focus on using inbuilt xml module in python for parsing XML.

Sample XML document

<data> <items> <item name="product1"></item> <item name="product2"></item> <item name="product3"></item> <item name="product4"></item> <item name="product5"></item> </items> </data>

Copy and paste the above xml code in a text file and save it as "data.xml" in working directory.

ElementTree XML API

The xml.etree.ElementTree module implements a simple and efficient API for parsing and creating XML data. The Element type is a flexible container object, designed to store hierarchical data structures in memory.

example

output

Minimal DOM implementation(xml.dom.minidom)

DOM Example

The xml.dom.minidom is a minimal implementation of the Document Object Model interface, with an API similar to that in other languages. It is intended to be simpler than the full DOM and also significantly smaller. Programmers who are not already proficient with the DOM should consider using the xml.etree.ElementTree module for their XML processing instead.

example

output









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.