4 py2
= sys
.version
[0] == '2'
6 from wxPython
.wx
import *
9 from xml
.parsers
import expat
12 from xml
.parsers
import pyexpat
13 parsermodule
= pyexpat
18 #----------------------------------------------------------------------
21 def runTest(frame
, nb
, log
):
22 dlg
= wxMessageDialog(frame
, 'This demo requires the XML package. '
23 'See http://www.python.org/sigs/xml-sig/',
24 'Sorry', wxOK | wxICON_INFORMATION
)
30 class XMLTree(wxTreeCtrl
):
31 def __init__(self
, parent
, ID
):
32 wxTreeCtrl
.__init
__(self
, parent
, ID
)
33 self
.nodeStack
= [self
.AddRoot("Root")]
35 # Define a handler for start element events
36 def StartElement(self
, name
, attrs
):
39 id = self
.AppendItem(self
.nodeStack
[-1], name
)
40 self
.nodeStack
.append(id)
42 def EndElement(self
, name
):
43 self
.nodeStack
= self
.nodeStack
[:-1]
45 def CharacterData(self
, data
):
46 if string
.strip(data
):
49 self
.AppendItem(self
.nodeStack
[-1], data
)
52 def LoadTree(self
, filename
):
54 Parser
= parsermodule
.ParserCreate()
56 # Tell the parser what the start element handler is
57 Parser
.StartElementHandler
= self
.StartElement
58 Parser
.EndElementHandler
= self
.EndElement
59 Parser
.CharacterDataHandler
= self
.CharacterData
62 ParserStatus
= Parser
.Parse(open(filename
,'r').read(), 1)
65 def runTest(frame
, nb
, log
):
67 win
.LoadTree("paper.xml")
70 #----------------------------------------------------------------------