I attach to you a example XML file to parse and the demo of my objective.
The iptRequest.xml is the file to parse in one mode. I can't parse it.
The demo.py is my ideal result, manually built, that should be built by parsing the XML.
How can i do to do it?
Bye all!
#!/usr/bin/env python # -*- coding: ISO-8859-15 -*- # generated by wxGlade 0.4 on Fri Jan 27 12:24:48 2006
from wxPython.wx import *
from wxPython.grid import *
class MyFrame(wxFrame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wxDEFAULT_FRAME_STYLE
wxFrame.__init__(self, *args, **kwds)
self.grid_1 = wxGrid(self, -1, size=(1, 1))
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.SetSize(wxDLG_SZE(self, (390, 136)))
self.grid_1.CreateGrid(8, 8)
self.grid_1.EnableDragColSize(0)
self.grid_1.SetColLabelValue(0, "Chain")
self.grid_1.SetColLabelValue(1, "Policy")
self.grid_1.SetColLabelValue(2, "Num")
self.grid_1.SetColLabelValue(3, "Target")
self.grid_1.SetColLabelValue(4, "Protocol")
self.grid_1.SetColLabelValue(5, "Option")
self.grid_1.SetColLabelValue(6, "Source")
self.grid_1.SetColLabelValue(7, "Destination")
self.grid_1.SetMinSize(wxDLG_SZE(self.grid_1, (387, 150)))
# end wxGlade
self.grid_1.SetCellValue(0,0,"INPUT")
self.grid_1.SetCellValue(1,0,"INPUT")
self.grid_1.SetCellValue(2,0,"INPUT")
self.grid_1.SetCellValue(3,0,"OUTPUT")
self.grid_1.SetCellValue(4,0,"OUTPUT")
self.grid_1.SetCellValue(5,0,"OUTPUT")
self.grid_1.SetCellValue(6,0,"FORWARD")
self.grid_1.SetCellValue(7,0,"FORWARD")
self.grid_1.SetCellValue(0,1,"ACCEPT")
self.grid_1.SetCellValue(1,1,"ACCEPT")
self.grid_1.SetCellValue(2,1,"ACCEPT")
self.grid_1.SetCellValue(3,1,"ACCEPT")
self.grid_1.SetCellValue(4,1,"ACCEPT")
self.grid_1.SetCellValue(5,1,"ACCEPT")
self.grid_1.SetCellValue(6,1,"ACCEPT")
self.grid_1.SetCellValue(7,1,"ACCEPT")
self.grid_1.SetCellValue(0,2,"1")
self.grid_1.SetCellValue(1,2,"2")
self.grid_1.SetCellValue(2,2,"3")
self.grid_1.SetCellValue(3,2,"1")
self.grid_1.SetCellValue(4,2,"2")
self.grid_1.SetCellValue(5,2,"3")
self.grid_1.SetCellValue(6,2,"1")
self.grid_1.SetCellValue(7,2,"2")
self.grid_1.SetCellValue(0,3,"ACCEPT")
self.grid_1.SetCellValue(1,3,"ACCEPT")
self.grid_1.SetCellValue(2,3,"ACCEPT")
self.grid_1.SetCellValue(3,3,"ACCEPT")
self.grid_1.SetCellValue(4,3,"ACCEPT")
self.grid_1.SetCellValue(5,3,"ACCEPT")
self.grid_1.SetCellValue(6,3,"ACCEPT")
self.grid_1.SetCellValue(7,3,"ACCEPT")
self.grid_1.SetCellValue(0,4,"icmp")
self.grid_1.SetCellValue(1,4,"tcp")
self.grid_1.SetCellValue(2,4,"udp")
self.grid_1.SetCellValue(3,4,"icmp")
self.grid_1.SetCellValue(4,4,"icmp")
self.grid_1.SetCellValue(5,4,"icmp")
self.grid_1.SetCellValue(6,4,"icmp")
self.grid_1.SetCellValue(7,4,"udp")
self.grid_1.SetCellValue(0,5,"--")
self.grid_1.SetCellValue(1,5,"--")
self.grid_1.SetCellValue(2,5,"--")
self.grid_1.SetCellValue(3,5,"--")
self.grid_1.SetCellValue(4,5,"--")
self.grid_1.SetCellValue(5,5,"--")
self.grid_1.SetCellValue(6,5,"--")
self.grid_1.SetCellValue(7,5,"--")
self.grid_1.SetCellValue(0,6,"localhost.localdomain")
self.grid_1.SetCellValue(1,6,"127.0.0.3")
self.grid_1.SetCellValue(2,6,"127.0.0.3")
self.grid_1.SetCellValue(3,6,"localhost.localdomain")
self.grid_1.SetCellValue(4,6,"127.0.0.2")
self.grid_1.SetCellValue(5,6,"127.0.0.3")
self.grid_1.SetCellValue(6,6,"localhost.localdomain")
self.grid_1.SetCellValue(7,6,"127.0.0.3")
self.grid_1.SetCellValue(0,7,"anywhere")
self.grid_1.SetCellValue(1,7,"anywhere")
self.grid_1.SetCellValue(2,7,"anywhere")
self.grid_1.SetCellValue(3,7,"anywhere")
self.grid_1.SetCellValue(4,7,"anywhere")
self.grid_1.SetCellValue(5,7,"anywhere")
self.grid_1.SetCellValue(6,7,"anywhere")
self.grid_1.SetCellValue(7,7,"anywhere")
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wxBoxSizer(wxVERTICAL)
sizer_1.Add(self.grid_1, 1, wxEXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
# end of class MyFrame
if __name__ == "__main__":
app = wxPySimpleApp(0)
wxInitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
<!DOCTYPE meshap-manager SYSTEM "MeshAP.dtd">
<meshap-manager>
<iptables-response>
<listtable>
<table chain="INPUT" policy="ACCEPT">
<rule num="1" target="ACCEPT" protocol="icmp" option="--" source="localhost.localdomain" destination="anywhere"/>
<rule num="2" target="ACCEPT" protocol="tcp" option="--" source="127.0.0.3" destination="anywhere"/>
<rule num="3" target="ACCEPT" protocol="udp" option="--" source="127.0.0.3" destination="anywhere"/>
</table>
<table chain="FORWARD" policy="ACCEPT">
<rule num="1" target="ACCEPT" protocol="icmp" option="--" source="localhost.localdomain" destination="anywhere"/>
<rule num="2" target="ACCEPT" protocol="icmp" option="--" source="127.0.0.2" destination="anywhere"/>
<rule num="3" target="ACCEPT" protocol="icmp" option="--" source="127.0.0.3" destination="anywhere"/>
</table>
<table chain="OUTPUT" policy="ACCEPT">
<rule num="1" target="ACCEPT" protocol="icmp" option="--" source="localhost.localdomain" destination="anywhere"/>
<rule num="2" target="ACCEPT" protocol="udp" option="--" source="127.0.0.3" destination="anywhere"/>
</table>
</listtable>
</iptables-response>
</meshap-manager>
-- http://mail.python.org/mailman/listinfo/python-list
