Re: lxml.etree, namespaces and element insertion



hein, 27.01.2011 19:16:
The other day i was processing an xml tree using lxml.etree. That tree
contained a namespace. During that processing i inserted an element.
Later on
i tried to find that element using xpath. And to my suprise that
element was
not found! Maybe my suprise is just the result of my marginal
knowledge about xml namespaces.

After some examination i found out that the reason for not finding the
element
was that i did not supply a namespace when inserting the element.
[...]
I have two questions on this:

- Is what i am seeing expected behavior?

Yes. It's a common problem for new users, though.


- How am i supposed to detect a missing namespace, if there are no
differences
in the serialized representation? (That's what i initially used to
debug the problem.)

This is a known problem of XML namespaces, which were only designed as an add-on to XML after the fact. The only advice I can give: be careful with the default namespace.

Stefan

.



Relevant Pages

  • Re: How to incorporate NULL values in an INSERT command? (easy question)
    ... To use these you need the correct namespace, so that may have been a secondary issue. ... Turns out the solution for inserting a GUID is simple, ... Once you incorporate this namespace you can ...
    (microsoft.public.sqlserver.server)
  • Re: How to incorporate NULL values in an INSERT command? (easy question)
    ... John...the solution was that I was missing a namespace! ... Turns out the solution for inserting a GUID is simple, ...
    (microsoft.public.sqlserver.server)
  • lxml namespaces problem
    ... I have a little problem with XML namespaces. ... The first one looks for nodes in 'ns1' ... namespace, and substitutes them, according to some algorithm. ... it confuses some other processors ...
    (comp.lang.python)
  • Re: XML and namespaces
    ... qualifiedName). ... creating a node with a namespace prefix and namespace URI, ... appropriate XML namespaces." ...
    (comp.lang.python)
  • Re: xml attributes question
    ... > i am trying to print the keys of a NamedNodeMap which contains the ... because of xml namespaces. ... caracterized by it's name and the namespace it belongs to. ...
    (comp.lang.python)