Re: [xml-bindings]call to 'newNs(...)'
- From: Daniel Veillard <veillard redhat com>
- To: rm fabula de
- Cc: xml-bindings gnome org
- Subject: Re: [xml-bindings]call to 'newNs(...)'
- Date: Mon, 19 Aug 2002 10:18:28 -0400
On Mon, Aug 19, 2002 at 04:20:42PM +0200, rm fabula de wrote:
> Hello list,
>
> i've encountered a strange problem with the
> libxml2 python bindings.
> While the following works:
>
> doc = libxml2.newDoc("1.0")
> root = doc.newChild(None, "doc", None)
> root.newNs("http://example.com/doc", "my")
>
> this doesn't:
>
> doc = libxml2.parseFile("example.xml")
> root=doc.children
> root.newNs("http://example.com/doc", "my")
>
> The error message reads as follows:
>
> Traceback (most recent call last):
> File "test.py", line 12, in ?
> root.newNs("http://example.com/doc", "my")
> File "/usr/local/lib/python2.1/site-packages/libxml2.py", line 1452, in newNs
> if ret == None:raise treeError('xmlNewNs() failed')
> libxml2.treeError: xmlNewNs() failed
>
>
> What am i missing ?
I don't know, I can't reproduce it myself with document.xml being a simple
<doc/> instance:
paphio:~/XML/python -> python
Python 1.5.2 (#1, Apr 3 2002, 18:16:26) [GCC 2.96 20000731 (Red Hat Linux 7.2 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import libxml2
>>> doc = libxml2.parseFile("example.xml")
>>> root=doc.children
>>> print root
<xmlNode (doc) object at 0x8112020>
>>> root.newNs("http://example.com/doc", "my")
<xmlNs (my) object at 0x8128450>
>>> doc.serialize()
'<?xml version="1.0"?>\012<doc xmlns:my="http://example.com/doc"/>\012'
>>>
make sure the "my" prefix ain't already defined on that node or
that parsing didn't generated an error. Note that doc.children may
not be the document root either if you have a DTD declaration, PIs or
other stuff before the root document, use doc.getRootElement() to be sure.
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]