From xmldom import minidom config minidomparseConfigfile

The next step is to find all <exception> elements. I know that their "parent" node is the <exception_types> element, so I need to get a list of those first. This can be done with the getElementsByTagName method, which is available for any XML object. This method accepts one argument, the name of the element you're trying to find. The result is a list of Element objects that have the name you searched for. The search performed by method is recursive, so if I start at the top level (which in my instance is the document object) it will return all elements that have this particular name. In that case I may as well search for the <exception> tag. With this simplistic configuration file that method would work as well, but the name exception is much too generic, and therefore may be used outside exception_types sections. Another important thing to note is that each Element object is also searchable and has the same method available to use. So I can go through the list of <exception_types> elements and drill down further, searching for an <exception> tag in each:

Was this article helpful?

0 0

Post a comment