Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Martin v. Loewis, 16.05.2010 11:05: Maybe true technically, but false in practice. If I receive XML data from source XYZ or service XYZ the use of namespaces and their prefixes is extremely consistent [in practice] and very customary (for example: I've never seen the DSML namespace abbreviated a

Re: Reading XML namespaces

2010-05-16 Thread Martin v. Loewis
> Maybe true technically, but false in practice. If I receive XML data > from source XYZ or service XYZ the use of namespaces and their prefixes > is extremely consistent [in practice] and very customary (for example: > I've never seen the DSML namespace abbreviated as anything other than > "dsml"

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Martin v. Loewis, 16.05.2010 09:07: the approach that the OP is apparently trying to follow is clearly misguided. I completely agree. However, I recommend that we let him find out on his own. I suspect he has some idiomatic usage of XML, perhaps with all namespace prefixes defined in the root

Re: Reading XML namespaces

2010-05-16 Thread Martin v. Loewis
> Well, there's an "nsmap" property on each Element that provides the > mapping of prefixes to namespace URIs that form the scope of the > Element. However, while this is what the OP asked for, it is not what > the OP wants, simply because it doesn't solve the problem. Well, it solves the problem

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 23:04: On Sat, 2010-05-15 at 22:58 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 22:40: On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http://www.dsml.or

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Adam Tauno Williams, 16.05.2010 06:00: Given that XML documents can be very large I'd rather avoid a parsing of the document [beyond what lxml/etree] has already done] just to retrieve the namespaces and their prefixes. In order to find out which prefixes are used in the document and which set

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Martin v. Loewis, 15.05.2010 23:37: BTW, I'm still not sure I understand your problem. Could you provide some more details? Wouldn't it be easier if you told the OP how to access the prefix mappings in lxml etree, or, if this was actually not possible, admitted that it is actually not possible?

Re: Reading XML namespaces

2010-05-15 Thread Adam Tauno Williams
On Sun, 2010-05-16 at 02:37 +0200, Martin v. Loewis wrote: > > ??? The namespaces are embedded in the document. Personally I find it > > odd I have to tell xpath about the namespace of the document it is a > > $*&@(*& method of. > How so? Why do you say it's a "method", and why do you say "of"? >

Re: Reading XML namespaces

2010-05-15 Thread Adam Tauno Williams
On Sat, 2010-05-15 at 23:37 +0200, Martin v. Loewis wrote: > > BTW, I'm still not sure I understand your problem. Could you provide > > some more details? > Wouldn't it be easier if you told the OP how to access the prefix :) > mappings in lxml etree, or, if this was actually not possible, admitt

Re: Reading XML namespaces

2010-05-15 Thread Martin v. Loewis
> ??? The namespaces are embedded in the document. Personally I find it > odd I have to tell xpath about the namespace of the document it is a > $*&@(*& method of. How so? Why do you say it's a "method", and why do you say "of"? Usually, xpath expressions are *not* part of the document they ope

Re: Reading XML namespaces

2010-05-15 Thread Adam Tauno Williams
On Sat, 2010-05-15 at 23:25 +0200, Stefan Behnel wrote: > Ah, you didn't provide that information in your initial post. So you > control neither the document nor the XPath expression, right? Correct. > Can't you get the namespace-prefix mapping from your user? Nope. Or they are not going to b

Re: Reading XML namespaces

2010-05-15 Thread Martin v. Loewis
> BTW, I'm still not sure I understand your problem. Could you provide > some more details? > Wouldn't it be easier if you told the OP how to access the prefix mappings in lxml etree, or, if this was actually not possible, admitted that it is actually not possible? FWIW, in the DOM, you look at a

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 23:04: On Sat, 2010-05-15 at 22:58 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 22:40: On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http://www.dsml.or

Re: Reading XML namespaces

2010-05-15 Thread Adam Tauno Williams
On Sat, 2010-05-15 at 22:58 +0200, Stefan Behnel wrote: > Adam Tauno Williams, 15.05.2010 22:40: > > On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: > >> Adam Tauno Williams, 15.05.2010 20:37: > >>> Say I have an XML document that begins with: > >>> > >>> http://www.dsml.org/DSML";> > >>>

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 22:40: On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http://www.dsml.org/DSML";> How can one access the namespaces define in this node? I've done a fair amount of XML

Re: Reading XML namespaces

2010-05-15 Thread Adam Tauno Williams
On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: > Adam Tauno Williams, 15.05.2010 20:37: > > Say I have an XML document that begins with: > > > > http://www.dsml.org/DSML";> > > How can one access the namespaces define in this node? I've done a fair > > amount of XML in Python, but haven'

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http://www.dsml.org/DSML";> ... How can one access the namespaces define in this node? I've done a fair amount of XML in Python, but haven't been able to uncover the call to enumerate the namespaces. Primaril

Reading XML namespaces

2010-05-15 Thread Adam Tauno Williams
Say I have an XML document that begins with: http://www.dsml.org/DSML";> ... How can one access the namespaces define in this node? I've done a fair amount of XML in Python, but haven't been able to uncover the call to enumerate the namespaces. Primarily I am using etree from lxml. -- Adam Ta