Module xmlhelper
[hide private]
[frames] | no frames]

Source Code for Module xmlhelper

 1  #============================================================================  
 2  #Name        : xmlhelper.py  
 3  #Part of     : Helium  
 4   
 5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
 6  #All rights reserved. 
 7  #This component and the accompanying materials are made available 
 8  #under the terms of the License "Eclipse Public License v1.0" 
 9  #which accompanies this distribution, and is available 
10  #at the URL "http://www.eclipse.org/legal/epl-v10.html". 
11  # 
12  #Initial Contributors: 
13  #Nokia Corporation - initial contribution. 
14  # 
15  #Contributors: 
16  # 
17  #Description: 
18  #=============================================================================== 
19   
20  import re 
21  import amara 
22  from xml.dom import Node 
23   
24 -def node_scan(node, name):
25 """ 26 Replacement function for node.xml_xpath('./name'). 27 name is a regular expression. 28 """ 29 results = [] 30 for subnode in node.childNodes: 31 if subnode.nodeType == Node.ELEMENT_NODE and re.match(name, subnode.nodeName) is not None: 32 results.append(subnode) 33 return results
34
35 -def recursive_node_scan(node, name):
36 """ 37 Replacement function for node.xml_xpath('.//name'). 38 name is a regular expression. 39 """ 40 results = node_scan(node, name) 41 for subnode in node.childNodes: 42 results.extend(recursive_node_scan(subnode, name)) 43 return results
44