blob: fae1d745bfd3d5e51564a120d4ebd055bc4c4433 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
"""
XML node parser
Copyright (C) 2022 Intel Corporation <www.intel.com>
Author: Lee, Kah Jing <[email protected]>
"""
import xml.dom
def isElementNode(XMLNode):
""" check if the node is element node """
return XMLNode.nodeType == xml.dom.Node.ELEMENT_NODE
def firstElementChild(XMLNode):
""" Calling firstChild on an Node of type Element often (always?)
returns a Node of Text type. How annoying! Return the first Element
child
"""
child = XMLNode.firstChild
while child != None and not isElementNode(child):
child = nextElementSibling(child)
return child
def nextElementSibling(XMLNode):
""" nextElementSibling will return the next sibling of XMLNode that is
an Element Node Type
"""
sib = XMLNode.nextSibling
while sib != None and not isElementNode(sib):
sib = sib.nextSibling
return sib
|