-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomxpath.py
More file actions
executable file
·77 lines (66 loc) · 1.87 KB
/
domxpath.py
File metadata and controls
executable file
·77 lines (66 loc) · 1.87 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#import xpathc
import domtreeimp
from functions import function_list
#from xml.dom.ext import Print
#import parserbackend
from xpathyylex import XPathLexer
import parser
class Environment :
def __init__(self, nsMap = {}, variables = {}, functions = {}) :
self.nsMap = dict(nsMap)
self.nsMap[None] = None
self.nsMap["*"] = "*"
self.functions = function_list
def Compile(e) :
#l = XPathLexer(e)
#print dir(l), str(l.func_closure), l.func_dict
#parser = xpathc.new()
#parser.verbose = True
expression = parser.parse(e)
#expression = xpathc.parse(parserbackend.__dict__, XPathLexer(e))
return expression(domtreeimp)
#return lambda node, nsMap : domtreeimp.evaluate(expression, node, nsMap)
doc = """<d_n_d_players>
<player>
<name>Joe</name>
<character>Rasputin</character>
</player>
<player>
<name>Scot</name>
<character>elstar</character>
</player>
</d_n_d_players>"""
doc = """<?xml version="1.0"?>
<root>
<anItem>1</anItem>
<anItem>2</anItem>
</root>"""
doc = """<?xml version="1.0"?>
<root hi="there">
<anItem hi="there">1</anItem>
<anItem hi="there" now="again">2</anItem>
</root>"""
doc2 = """<?xml version="1.0"?><one><two>Three</two><two/></one>"""
if __name__ == "__main__" :
#from xml.dom.ext.reader import Sax2
from xml.dom.minidom import parseString
from trace import trace
#reader = Sax2.Reader()
#doc1 = reader.fromString(doc)
doc2 = parseString(doc)
#doc = reader.fromSt("DnD.xml")
#expr = Compile("/d_n_d_players/player/../../d_n_d_players/player/character")
expr = Compile("/root/*")
#expr = Compile(" 2 + 5 * 3")
#for n in range(1) :
# if n % 100 == 0 :
# print ".",
# for i in expr(doc, Environment()) :
# Print (i)
# print
# #pass
result = expr(trace(doc2), Environment())
print repr(result)
for r in result:
print repr(r)
#expr(test_doc, Environment())