Big HELP Request - Insert parsed XML in a GRID

Hi all.
I’ve wrote a recursive function that parse a xml file.
The function is at end of mail.
The XML file to parse is attached.
In this function i don’t consider the content of the element, because in my project the elements are empty, the information is saved in attributes.

I would dinamically create a wxFrame that visualize my parsed XML in nice view.
I thought that a wxGRID is the best way but i’m not sure.
My problems is about the dinamically of representation.
I have more questions like “How can i fix the row of grid? And how can i insert the value in CellValue? etc”

Is there anyone of you that can make this, or can post an example about this?
I’ve only a little bit of time so i’ve post this big help on list…
If anyone of you can help me i could insert him in collaborators list of my project!!

import sys, string
from xml.dom import minidom, Node
**def** walk(parent,level):
	**for** node **in** parent.childNodes:
		**if** node.nodeType==Node.ELEMENT_NODE:
			**print** "\nElement: %s" %
node.nodeName
attrs=			node.attributes
**for** attrName **in** attrs.keys():
				attrNode=attrs.get(attrName)
				attrValue=				attrNode.nodeValue
**print** "Attribute: %s Value: %s
 " %(attrName,attrValue)
			walk(node, level+1)
**def** run ():
	doc=minidom.parse("iptResponse.xml"
)
	rootNode=	doc.documentElement
level=0
	walk(rootNode,level)
run()

iptResponse.xml (1.23 KB)

···


Sbaush

Hi all.
I've wrote a recursive function that parse a xml file.
The function is at end of mail.
The XML file to parse is attached.
In this function i don't consider the content of the element, because in my
project the elements are empty, the information is saved in attributes.

I would dinamically create a wxFrame that visualize my parsed XML in nice
view.
I thought that a wxGRID is the best way but i'm not sure.
My problems is about the dinamically of representation.
I have more questions like "How can i fix the row of grid? And how can i
insert the value in CellValue? etc"

grid.AppendRows(1)
row = grid.GetNumberRows()-1

for col, value in enumerate(values):
    grid.SetCellValue(row, col, value)

Read the documentation.

Is there anyone of you that can make this, or can post an example about
this?
I've only a little bit of time so i've post this big help on list...
If anyone of you can help me i could insert him in collaborators list of my
project!!

Why do you need help? You have node names (node.nodeName), you have
node attributes (attrs.keys()), and you can call wxPython object
creation in there. Create a row with wx.Grid() whenever you get a
node.nodeName of 'rule', and set the values on that row by going through
your list of columns.

···

Sbaush <sbaush@gmail.com> wrote:

import sys, stringfrom xml.dom import minidom, Node

*def* walk(parent,level):
  *for* node *in* parent.childNodes:
    *if* node.nodeType==Node.ELEMENT_NODE:
      *print* "\nElement: %s" %node.nodeName
      attrs=node.attributes
      *for* attrName *in* attrs.keys():
        attrNode=attrs.get(attrName)
        attrValue=attrNode.nodeValue
        *print* "Attribute: %s Value: %s " %(attrName,attrValue)
      walk(node, level+1)*def* run ():
  doc=minidom.parse("iptResponse.xml")
  rootNode=doc.documentElement
  level=0
  walk(rootNode,level)

run()

--
Sbaush

Thanks!
Another question: in my parser the attributes are in a strange order, for
example the element <rule num="1" target="ACCEPT" protocol="icmp"
option="--" source="localhost.localdomain" destination="anywhere"/> is
parsed

Element: rule
Attribute: protocol Value: icmp
Attribute: target Value: ACCEPT
Attribute: destination Value: anywhere
Attribute: source Value: localhost.localdomain
Attribute: num Value: 1
Attribute: option Value: --
.
WHY the first is protocol, the second is targer etc???
WHY is not num the first?

Because the attributes are stored in a dictionary, and in Python, a
dictionary is a hash table, which has no explicit guarantees about
ordering. If you care about ordering...

    x = ('num', 'target', 'protocol', 'option', 'source', 'destination')
    for name in x:
        value = attrs.get(name)

- Josiah

···

Sbaush <sbaush@gmail.com> wrote:

Here is the parser

import sys, string
from xml.dom import minidom, Node

*def* walk(parent,level):
  *for* node *in* parent.childNodes:
    *if* node.nodeType==Node.ELEMENT_NODE:
      *print* "\nElement: %s" %
node.nodeName
      attrs=node.attributes
      *for* attrName *in* attrs.keys():
        attrNode=attrs.get(attrName)
        attrValue=attrNode.nodeValue
        *print* "Attribute: %s Value: %s
" %(attrName,attrValue)
      walk(node, level+1)
*def* run ():
  doc=minidom.parse("iptResponse.xml"
)
  rootNode=doc.documentElement
  level=0
  walk(rootNode,level)

run

2006/1/28, Josiah Carlson <jcarlson@uci.edu>:
>
>
> Sbaush <sbaush@gmail.com> wrote:
> > Hi all.
> > I've wrote a recursive function that parse a xml file.
> > The function is at end of mail.
> > The XML file to parse is attached.
> > In this function i don't consider the content of the element, because in
> my
> > project the elements are empty, the information is saved in attributes.
> >
> > I would dinamically create a wxFrame that visualize my parsed XML in
> nice
> > view.
> > I thought that a wxGRID is the best way but i'm not sure.
> > My problems is about the dinamically of representation.
> > I have more questions like "How can i fix the row of grid? And how can i
> > insert the value in CellValue? etc"
>
> grid.AppendRows(1)
> row = grid.GetNumberRows()-1
>
> for col, value in enumerate(values):
> grid.SetCellValue(row, col, value)
>
> Read the documentation.
>
> > Is there anyone of you that can make this, or can post an example about
> > this?
> > I've only a little bit of time so i've post this big help on list...
> > If anyone of you can help me i could insert him in collaborators list of
> my
> > project!!
>
> Why do you need help? You have node names (node.nodeName), you have
> node attributes (attrs.keys()), and you can call wxPython object
> creation in there. Create a row with wx.Grid() whenever you get a
> node.nodeName of 'rule', and set the values on that row by going through
> your list of columns.
>
>
>
>
> > import sys, stringfrom xml.dom import minidom, Node
> >
> > *def* walk(parent,level):
> > *for* node *in* parent.childNodes:
> > *if* node.nodeType==Node.ELEMENT_NODE:
> > *print* "\nElement: %s" %node.nodeName
> > attrs=node.attributes
> > *for* attrName *in* attrs.keys():
> > attrNode=attrs.get(attrName)
> > attrValue=attrNode.nodeValue
> > *print* "Attribute: %s Value: %s "
> %(attrName,attrValue)
> > walk(node, level+1)*def* run ():
> > doc=minidom.parse("iptResponse.xml")
> > rootNode=doc.documentElement
> > level=0
> > walk(rootNode,level)
> >
> > run()
> >
> >
> >
> >
> > --
> > Sbaush
>
>

--
Sbaush

Thanks you’re great!

···

2006/1/28, Josiah Carlson jcarlson@uci.edu:

Sbaush sbaush@gmail.com wrote:

Thanks!
Another question: in my parser the attributes are in a strange order, for
example the element <rule num=“1” target=“ACCEPT” protocol=“icmp”

option=“–” source=“localhost.localdomain” destination=“anywhere”/> is
parsed

Element: rule
Attribute: protocol Value: icmp
Attribute: target Value: ACCEPT

Attribute: destination Value: anywhere
Attribute: source Value: localhost.localdomain
Attribute: num Value: 1
Attribute: option Value: –
.
WHY the first is protocol, the second is targer etc???

WHY is not num the first?

Because the attributes are stored in a dictionary, and in Python, a
dictionary is a hash table, which has no explicit guarantees about
ordering. If you care about ordering…

x = ('num', 'target', 'protocol', 'option', 'source', 'destination')
for name in x:
    value = attrs.get(name)
  • Josiah

Here is the parser

import sys, string

from xml.dom import minidom, Node

def walk(parent,level):
for node in parent.childNodes:
if node.nodeType==Node.ELEMENT_NODE:
print “\nElement: %s” %

node.nodeName
attrs=node.attributes
for attrName in attrs.keys():
attrNode=attrs.get(attrName)
attrValue=
attrNode.nodeValue
print "Attribute: %s Value: %s
" %(attrName,attrValue)
walk(node, level+1)
def run ():
doc=
minidom.parse(“iptResponse.xml”
)
rootNode=doc.documentElement
level=0
walk(rootNode,level)

run

2006/1/28, Josiah Carlson <
jcarlson@uci.edu>:

Sbaush sbaush@gmail.com wrote:

Hi all.
I’ve wrote a recursive function that parse a xml file.

The function is at end of mail.
The XML file to parse is attached.
In this function i don’t consider the content of the element, because in
my
project the elements are empty, the information is saved in attributes.

I would dinamically create a wxFrame that visualize my parsed XML in
nice
view.
I thought that a wxGRID is the best way but i’m not sure.

My problems is about the dinamically of representation.
I have more questions like “How can i fix the row of grid? And how can i
insert the value in CellValue? etc”

grid.AppendRows(1)
row = grid.GetNumberRows()-1

for col, value in enumerate(values):
grid.SetCellValue(row, col, value)

Read the documentation.

Is there anyone of you that can make this, or can post an example about
this?
I’ve only a little bit of time so i’ve post this big help on list…
If anyone of you can help me i could insert him in collaborators list of

my

project!!

Why do you need help? You have node names (node.nodeName), you have
node attributes (attrs.keys()), and you can call wxPython object

creation in there. Create a row with wx.Grid() whenever you get a
node.nodeName of ‘rule’, and set the values on that row by going through
your list of columns.

import sys, stringfrom xml.dom import minidom, Node

def walk(parent,level):
for node in parent.childNodes:

          *if* node.nodeType==Node.ELEMENT_NODE:
                  *print* "\nElement: %s" %node.nodeName
                  attrs=node.attributes
                  *for* attrName *in* attrs.keys():
                          attrNode=attrs.get(attrName)
                          attrValue=attrNode.nodeValue
                          *print* "Attribute: %s Value: %s "

%(attrName,attrValue)

                  walk(node, level+1)*def* run ():
  doc=

minidom.parse(“iptResponse.xml”)

  rootNode=doc.documentElement
  level=0
  walk(rootNode,level)

run()


Sbaush


Sbaush


Sbaush