

{"id":15387,"date":"2018-05-24T06:05:01","date_gmt":"2018-05-24T00:35:01","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=15387"},"modified":"2021-03-08T18:45:52","modified_gmt":"2021-03-08T13:15:52","slug":"python-xml-parser","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/","title":{"rendered":"Python XML Parser &#8211; XML Processing with Python 3"},"content":{"rendered":"<p>In this Python XML Parser Tutorial, we will study what is Python XML Processing.<\/p>\n<p>Moreover, we will study the Python XML Parser Architecture and API and Python XML FIle. Along with this, we will learn Python Parsing XML with DOM and SAX.<\/p>\n<p>So, let&#8217;s start Python XML Parser Tutorial.<\/p>\n<div id=\"attachment_15416\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15416\" class=\"wp-image-15416 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg\" alt=\"Python XML Parser - XML Processing with Python 3\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-15416\" class=\"wp-caption-text\">Python XML Parser &#8211; XML Processing with Python 3<\/p><\/div>\n<h2><span style=\"font-weight: 400\">What is XML?\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400\"><em>Extensible Markup Language (XML)<\/em> is a markup language which encodes documents by defining a set of rules in both machine-readable and human-readable format.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Extended from <em>SGML (Standard Generalized Markup Language)<\/em>, it lets us describe the structure of the document. In XML, we can define custom tags. <\/span><\/p>\n<p><span style=\"font-weight: 400\">We can also use XML as a standard format to exchange information.<\/span><\/p>\n<h3>Python XML Parser Architecture and API<\/h3>\n<p><span style=\"font-weight: 400\">Like we mentioned earlier, we will make use of two APIs to deal with Python XML Parser here- SAX and DOM.<\/span><\/p>\n<h4>1. SAX (Simple API for XML)<\/h4>\n<p><span style=\"font-weight: 400\">When we have large documents or memory limitations, we can register callbacks for certain events. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Then, we can let the parser to parse the file as reading it from the disk. Because of this, it never stores the entire file in the memory. It is read-only.<\/span><\/p>\n<h4>2. DOM (Document Object Model API)<\/h4>\n<p><span style=\"font-weight: 400\">A W3C recommendation, DOM can represent all features of an XML document by reading an entire file into memory and storing it hierarchically. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This is the faster choice when working with large files. For a large project, you can use both, as they complement each other. But using this on too many small files can suck your resources up.<\/span><\/p>\n<h3>Python XML File<\/h3>\n<p><span style=\"font-weight: 400\">This is the Python XML file we\u2019re going to use:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=\"1.0\"?&gt;\r\n&lt;genre catalogue=\"Pop\"&gt;\r\n&lt;song title=\"No Tears Left to Cry\"&gt;\r\n&lt;artist&gt;Ariana Grande&lt;\/artist&gt;\r\n&lt;year&gt;2018&lt;\/year&gt;\r\n&lt;album&gt;Sweetener&lt;\/album&gt;\r\n&lt;\/song&gt;\r\n&lt;song title=\"Delicate\"&gt;\r\n&lt;artist&gt;Taylor Swift&lt;\/artist&gt;\r\n&lt;year&gt;2018&lt;\/year&gt;\r\n&lt;album&gt;Reputation&lt;\/album&gt;\r\n&lt;\/song&gt;\r\n&lt;song title=\"Mrs. Potato Head\"&gt;\r\n&lt;artist&gt;Melanie Martinez&lt;\/artist&gt;\r\n&lt;year&gt;2015&lt;\/year&gt;\r\n&lt;album&gt;Cry Baby&lt;\/album&gt;\r\n&lt;\/song&gt;\r\n&lt;\/genre&gt;<\/pre>\n<p><span style=\"font-weight: 400\">We have saved it as <strong>songs.xml<\/strong> on our Desktop<\/span><\/p>\n<div id=\"attachment_15417\" style=\"width: 1373px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/songs.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15417\" class=\"wp-image-15417 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/songs.png\" alt=\"Python XML Parser\" width=\"1363\" height=\"579\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/songs.png 1363w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/songs-150x64.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/songs-300x127.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/songs-768x326.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/songs-1024x435.png 1024w\" sizes=\"auto, (max-width: 1363px) 100vw, 1363px\" \/><\/a><p id=\"caption-attachment-15417\" class=\"wp-caption-text\">Python XML Parser- XML File<\/p><\/div>\n<p><span style=\"font-weight: 400\">This stores a collection of songs in the genre Pop. The ones we have currently include the songs No Tears left To Cry, Delicate, and Mrs. Potato Head.<\/span><\/p>\n<h3>Python XML Parser with DOM<\/h3>\n<p><span style=\"font-weight: 400\"><em>DOM stands for Document Object Model<\/em> and is a cross-language API from the W3C that lets us access and modify XML documents. <\/span><\/p>\n<p><span style=\"font-weight: 400\">We can use it for random-access applications. While with SAX, you can only ever access one SAX element at once.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s use the xml.dom module to load an XML document and create a minidom object. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Then, using the parser() method, we can create a DOM tree from this document.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from xml.dom.minidom import parse\r\n&gt;&gt;&gt; import xml.dom.minidom\r\n&gt;&gt;&gt; import os\r\n&gt;&gt;&gt; os.chdir('C:\\\\Users\\\\lifei\\\\Desktop')\r\n&gt;&gt;&gt; DOMTree = xml.dom.minidom.parse(\"songs.xml\") #Opening the XML document\r\n&gt;&gt;&gt; genre=DOMTree.documentElement\r\n&gt;&gt;&gt; if genre.hasAttribute('catalogue'):\r\nprint(f'Root: {genre.getAttribute(\"catalogue\")}')\r\nRoot: Pop\r\n&gt;&gt;&gt; songs=genre.getElementsByTagName('song') #Get all songs in the genre Pop\r\n&gt;&gt;&gt; for song in songs: #Print each song\u2019s details\r\nprint('Song:')\r\nif song.hasAttribute('title'):\r\nprint(f'Title: {song.getAttribute(\"title\")}')\r\nartist=song.getElementsByTagName('artist')[0]\r\nprint(f'Artist: {artist.firstChild.data}')\r\nyear=song.getElementsByTagName('year')[0]\r\nprint(f'Release Year: {year.firstChild.data}')\r\nalbum=song.getElementsByTagName('album')[0]\r\nprint(f'Album: {album.firstChild.data}')<\/pre>\n<p><strong style=\"font-family: Verdana, Geneva, sans-serif\">Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">Song:<\/span><br \/>\n<span style=\"font-weight: 400\">Title: No Tears Left to Cry<\/span><br \/>\n<span style=\"font-weight: 400\">Artist: Ariana Grande<\/span><br \/>\n<span style=\"font-weight: 400\">Release Year: 2018<\/span><br \/>\n<span style=\"font-weight: 400\">Album: Sweetener<\/span><br \/>\n<span style=\"font-weight: 400\">Song:<\/span><br \/>\n<span style=\"font-weight: 400\">Title: Delicate<\/span><br \/>\n<span style=\"font-weight: 400\">Artist: Taylor Swift<\/span><br \/>\n<span style=\"font-weight: 400\">Release Year: 2018<\/span><br \/>\n<span style=\"font-weight: 400\">Album: Reputation<\/span><br \/>\n<span style=\"font-weight: 400\">Song:<\/span><br \/>\n<span style=\"font-weight: 400\">Title: Mrs. Potato Head<\/span><br \/>\n<span style=\"font-weight: 400\">Artist: Melanie Martinez<\/span><br \/>\n<span style=\"font-weight: 400\">Release Year: 2015<\/span><br \/>\n<span style=\"font-weight: 400\">Album: Cry Baby<\/span><\/div>\n<h3>Python XML Parser with\u00a0SAX<\/h3>\n<p><span style=\"font-weight: 400\"><em>SAX is a standard interface<\/em> and will help you with event-driven XML parsing. You\u2019ll need to subclass <strong>xml.sax.ContentHandler<\/strong> to create a ContentHandler for this purpose. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This will handle your tags and attributes and will also serve methods for handling parsing events. The Python XML parser that owns it calls these methods parsing the XML file.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s look at some of these methods. <\/span><span style=\"font-weight: 400\">When it begins parsing the file, it calls startDocument(), and calls endDocument() when ending the parsing at the end of the file. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, it passes the XML file\u2019s character data as a parameter to the characters(text) method.<\/span><\/p>\n<p><span style=\"font-weight: 400\">At the start and end of each element, it calls the ContentHandler. If the Python XML parser is in namespace mode, it calls methods startElementNS() and endElementNS(). <\/span><\/p>\n<p><span style=\"font-weight: 400\">Otherwise, it calls startElement(tag, attributes) and endElement(tag), where a tag is the element tag and attributes is an Attributes object.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, in Python XML Processing, let\u2019s take a look at few methods first.<\/span><\/p>\n<div id=\"attachment_15424\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15424\" class=\"wp-image-15424 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01.jpg\" alt=\"Python XML Parser\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Parsing-XML-with-SAX-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-15424\" class=\"wp-caption-text\">Python XML Pearser- methods os parsing with SAX<\/p><\/div>\n<h4>1. make_parser()<\/h4>\n<p><span style=\"font-weight: 400\">This method creates and returns a parser of the first type the system can find. This is the syntax:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">xml.sax.make_parser([parser_list])<\/pre>\n<p><span style=\"font-weight: 400\">It takes a list of parsers to be used.<\/span><\/p>\n<h4>2. parse()<\/h4>\n<p><span style=\"font-weight: 400\">This uses the following syntax:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">xml.sax.parse(xmlfile,contenthandler[,errorhandler])<\/pre>\n<p><span style=\"font-weight: 400\">This creates a SAX parser and then uses it in parsing the document specified by the parameter <\/span><i><span style=\"font-weight: 400\">xmlfile<\/span><\/i><span style=\"font-weight: 400\">. contenthandler is a ContentHandler object and errorhandler is a SAX ErrorHandler object.<\/span><\/p>\n<h4>3. parseString()<\/h4>\n<p><span style=\"font-weight: 400\">This method creates a SAX parser and parses an XML string. It has the following syntax:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">xml.sax.parseString(xmlstring,contenthandler[,errorhandler])<\/pre>\n<p><span style=\"font-weight: 400\">The parameter <\/span><i><span style=\"font-weight: 400\">xmlstring<\/span><\/i><span style=\"font-weight: 400\"> is the XML string to read from and the other two parameters are the same as above.<\/span><\/p>\n<p><strong>Example<\/strong><br \/>\n<span style=\"font-weight: 400\">Now, let\u2019s take an example program to parse an XML document using SAX.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import xml.sax\r\n&gt;&gt;&gt; class SongHandler(xml.sax.ContentHandler):\r\ndef __init__(self):\r\nself.CurrentData=''\r\nself.artist=''\r\nself.year=''\r\nself.album=''\r\ndef startElement(self,tag,attributes):\r\nself.CurrentData=tag\r\nif tag=='song':\r\nprint('Song:')\r\ntitle=attributes['title']\r\nprint(f'Title: {title}')\r\ndef endElement(self,tag):\r\nif self.CurrentData=='artist':\r\nprint(f'Artist: {self.artist}')\r\nelif self.CurrentData=='year':\r\nprint(f'Year: {self.year}')\r\nelif self.CurrentData=='album':\r\nprint(f'Album: {self.album}')\r\nself.CurrentData=''\r\ndef Characters(self,content):\r\nif self.CurrentData=='artist':\r\nself.artist=content\r\nelif self.CurrentData=='year':\r\nself.year=content\r\nelif self.CurrentData=='album':\r\nself.album=content\r\n&gt;&gt;&gt; if __name__=='__main__':\r\nparser=xml.sax.make_parser() #creating an XMLReader\r\nparser.setFeature(xml.sax.handler.feature_namespaces,0) #turning off namespaces\r\nHandler=SongHandler()\r\nparser.setContentHandler(Handler) #overriding default ContextHandler\r\nparser.parse('songs.xml')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">Song:<\/span><br \/>\n<span style=\"font-weight: 400\">Title: No Tears Left to Cry<\/span><br \/>\n<span style=\"font-weight: 400\">Artist: Ariana Grande<\/span><br \/>\n<span style=\"font-weight: 400\">Year: 2018<\/span><br \/>\n<span style=\"font-weight: 400\">Album: Sweetener<\/span><br \/>\n<span style=\"font-weight: 400\">Song:<\/span><br \/>\n<span style=\"font-weight: 400\">Title: Delicate<\/span><br \/>\n<span style=\"font-weight: 400\">Artist: Taylor Swift<\/span><br \/>\n<span style=\"font-weight: 400\">Year: 2018<\/span><br \/>\n<span style=\"font-weight: 400\">Album: Reputation<\/span><br \/>\n<span style=\"font-weight: 400\">Song:<\/span><br \/>\n<span style=\"font-weight: 400\">Title: Mrs. Potato Head<\/span><br \/>\n<span style=\"font-weight: 400\">Artist: Melanie Martinez<\/span><br \/>\n<span style=\"font-weight: 400\">Year: 2015<\/span><br \/>\n<span style=\"font-weight: 400\">Album: Cry Baby<\/span><\/div>\n<p><span style=\"font-family: Verdana, Geneva, sans-serif;font-weight: inherit\">So, this was all about Python XML Parser\u00a0tutorial. Hope you like our explanation.<\/span><\/p>\n<h3>Python Interview Questions on XML Processing<\/h3>\n<ol>\n<li>How do you process XML in Python?<\/li>\n<li>How to open a XML file in Python?<\/li>\n<li>How to pass XML parameter in Python?<\/li>\n<li>How do you add sub elements in XML in Python?<\/li>\n<li>Which module can you use\u00a0 to parse an XML file using Python?<\/li>\n<\/ol>\n<h2><span style=\"font-weight: 400\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Hence, we have a complete understanding of XML processing in Python 3. In addition, we studied Python XML parser architecture and Python XML file. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In addition, we studied\u00a0<\/span><span style=\"font-weight: 400\">2 API for Python XML Parser that is SAX and DOM. Also,. At last, we discussed methods of SAS XML Parser. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Furthermore, if you have any query, feel free to ask in the comment section.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python XML Parser Tutorial, we will study what is Python XML Processing. Moreover, we will study the Python XML Parser Architecture and API and Python XML FIle. Along with this, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":15416,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[4032,4199,7159,9416,9417,10345,10903,10930,10931,10932,12387,12388,16039,16309,16311,16312,16314,16316,16317],"class_list":["post-15387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-dom","tag-etensible-markup-language","tag-introduction-to-xml","tag-parsing-xml-with-dom","tag-parsing-xml-with-sax","tag-python-3-xml","tag-python-tutorial","tag-python-xml","tag-python-xml-library","tag-python-xml-processing","tag-sax","tag-sax-xml-parser","tag-what-is-xml","tag-xml","tag-xml-dom","tag-xml-file","tag-xml-parser","tag-xml-processing","tag-xml-processing-in-python-3"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python XML Parser - XML Processing with Python 3 - DataFlair<\/title>\n<meta name=\"description\" content=\"Python XML parser - what is Python XML Processing, Python XML file, API for Python XML Parser- XML with SAX, Parsing XML with DOM, methods in SAX XML Parser\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-xml-parser\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python XML Parser - XML Processing with Python 3 - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python XML parser - what is Python XML Processing, Python XML file, API for Python XML Parser- XML with SAX, Parsing XML with DOM, methods in SAX XML Parser\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-xml-parser\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-24T00:35:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-08T13:15:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python XML Parser - XML Processing with Python 3 - DataFlair","description":"Python XML parser - what is Python XML Processing, Python XML file, API for Python XML Parser- XML with SAX, Parsing XML with DOM, methods in SAX XML Parser","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/","og_locale":"en_US","og_type":"article","og_title":"Python XML Parser - XML Processing with Python 3 - DataFlair","og_description":"Python XML parser - what is Python XML Processing, Python XML file, API for Python XML Parser- XML with SAX, Parsing XML with DOM, methods in SAX XML Parser","og_url":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-05-24T00:35:01+00:00","article_modified_time":"2021-03-08T13:15:52+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python XML Parser &#8211; XML Processing with Python 3","datePublished":"2018-05-24T00:35:01+00:00","dateModified":"2021-03-08T13:15:52+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/"},"wordCount":925,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg","keywords":["DOM","Etensible Markup Language","Introduction TO XML","Parsing XML with DOM","Parsing XML with SAX","python 3 XML","python tutorial","python XML","Python XML library","Python XML Processing","SAX","SAX XML Parser","what is XML","XML","XML DOM","XML file","XML Parser","XML processing","XML processing in Python 3"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-xml-parser\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/","url":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/","name":"Python XML Parser - XML Processing with Python 3 - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg","datePublished":"2018-05-24T00:35:01+00:00","dateModified":"2021-03-08T13:15:52+00:00","description":"Python XML parser - what is Python XML Processing, Python XML file, API for Python XML Parser- XML with SAX, Parsing XML with DOM, methods in SAX XML Parser","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-xml-parser\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/XML-Processing-in-Python-3-01.jpg","width":1200,"height":628,"caption":"Python XML Processing"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-xml-parser\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python XML Parser &#8211; XML Processing with Python 3"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=15387"}],"version-history":[{"count":11,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15387\/revisions"}],"predecessor-version":[{"id":147849,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15387\/revisions\/147849"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/15416"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=15387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=15387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=15387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}