Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

xml depth python

>>> from xml.etree.ElementTree import XMLParser
>>> class MaxDepth:                     # The target object of the parser
...     maxDepth = 0
...     depth = 0
...     def start(self, tag, attrib):   # Called for each opening tag.
...         self.depth += 1
...         if self.depth > self.maxDepth:
...             self.maxDepth = self.depth
...     def end(self, tag):             # Called for each closing tag.
...         self.depth -= 1
...     def data(self, data):
...         pass            # We do not need to do anything with data.
...     def close(self):    # Called when all data has been parsed.
...         return self.maxDepth
...
>>> target = MaxDepth()
>>> parser = XMLParser(target=target)
>>> exampleXml = """
... <a>
...   <b>
...   </b>
...   <b>
...     <c>
...       <d>
...       </d>
...     </c>
...   </b>
... </a>"""
>>> parser.feed(exampleXml)
>>> parser.close()
4
Comment

PREVIOUS NEXT
Code Example
Python :: handwritten digits data set 
Python :: binary to octal in python 
Python :: how to kill somene 
Python :: latest version of python 
Python :: tables in python 
Python :: python 3 slice reverse 
Python :: using Decorators 
Python :: python curl 
Python :: pil format multiline text 
Python :: python __lt__ 
Python :: append 1 colimn in pandas df 
Python :: making ckeditor django responsive 
Python :: soustraire deux listes python 
Python :: how to use if else in python 
Python :: python set python key default 
Python :: adam optimizer keras learning rate degrade 
Python :: pylab plotting data 
Python :: python to postgresql 
Python :: python t test 
Python :: import module python same directory 
Python :: python selenium print element 
Python :: python gaussian filter 
Python :: list in one line of text in python 
Python :: python namedtuples 
Python :: how to sort values by index pandas 
Python :: how to serach for multiple attributes in xpath selenium python 
Python :: stack more system in python 
Python :: stop flask server 
Python :: django class based views 
Python :: python google docs api how to get doc index 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =