[sage-devel] Re: Parsing XML in Sage

2013-09-23 Thread Bill Janssen
I have an spkg for lxml (required for JModelica) and I intend to make it 
available in the near future.

Bill

On Tuesday, September 17, 2013 4:45:22 AM UTC-7, Nathann Cohen wrote:

 Hell everybody !

 We have in Sage an interface with ISGCI [1], and most of the code it 
 contains amounts to parsing a xml file, i.e. the db it gives access to. The 
 code is (very) ugly, and a friend of mine told me that I should use some 
 Python library to objectify this XML file, so that we only need work with 
 dictionaries (and not with the XML file) in the code.

 It looks like lxml would do the job, and there are others like gnosis or 
 amara that seem to do the same kind of things.

 Did you ever use any of those, and would you think it a good idea to add 
 them into Sage ? It would definitely simplify this code, at least.. :-)

 By the way, this interface is being patched by #14396, and it would be 
 great if somebody was willing to give it a review... The db's author has 
 been very kind with us, and the improvements I promised him are not 
 available in Sage yet ^^;

 Have fun :-)

 Nathann

 [1] http://graphclasses.org/


-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


[sage-devel] Re: Parsing XML in Sage

2013-09-17 Thread Volker Braun
I would suggest that you start with Python's own xml.etree:


import xml.etree.cElementTree as ET
tree = ET.ElementTree(file='document.xml')
root = tree.getroot()
for child in root:
print(child.tag, child.attrib)



On Tuesday, September 17, 2013 12:45:22 PM UTC+1, Nathann Cohen wrote:

 Hell everybody !

 We have in Sage an interface with ISGCI [1], and most of the code it 
 contains amounts to parsing a xml file, i.e. the db it gives access to. The 
 code is (very) ugly, and a friend of mine told me that I should use some 
 Python library to objectify this XML file, so that we only need work with 
 dictionaries (and not with the XML file) in the code.

 It looks like lxml would do the job, and there are others like gnosis or 
 amara that seem to do the same kind of things.

 Did you ever use any of those, and would you think it a good idea to add 
 them into Sage ? It would definitely simplify this code, at least.. :-)

 By the way, this interface is being patched by #14396, and it would be 
 great if somebody was willing to give it a review... The db's author has 
 been very kind with us, and the improvements I promised him are not 
 available in Sage yet ^^;

 Have fun :-)

 Nathann

 [1] http://graphclasses.org/


-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sage-devel] Re: Parsing XML in Sage

2013-09-17 Thread Nathann Cohen
 I would suggest that you start with Python's own xml.etree:

 import xml.etree.cElementTree as ET
 tree = ET.ElementTree(file='document.xml')
 root = tree.getroot()
 for child in root:
 print(child.tag, child.attrib)

I will never understand how XML can be so awful to use in Python or in any
language.

And I just noticed that .tag and .attrib methods do not appear in the
tab-completion.

Which may explain a lot of things _

Is there a reason for that ?

Nathann

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sage-devel] Re: Parsing XML in Sage

2013-09-17 Thread Vincent Delecroix
Here is an answer
{{{
sage: class A(object):
: def __getattribute__(self, name):
: return name
:
sage: a = A()
sage: a.b
'b'
sage: a.nathann
'nathann'
}}}
Actually, the tab completion looks really funny on this object!

2013/9/17, Nathann Cohen nathann.co...@gmail.com:
 I would suggest that you start with Python's own xml.etree:

 import xml.etree.cElementTree as ET
 tree = ET.ElementTree(file='document.xml')
 root = tree.getroot()
 for child in root:
 print(child.tag, child.attrib)

 I will never understand how XML can be so awful to use in Python or in any
 language.

 And I just noticed that .tag and .attrib methods do not appear in the
 tab-completion.

 Which may explain a lot of things _

 Is there a reason for that ?

 Nathann

 --
 You received this message because you are subscribed to the Google Groups
 sage-devel group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sage-devel+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-devel@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-devel.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.