473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

questions using libxml2

Hello,

I was hoping that someone here can please answer two questions
concerning libxml2 python module use:

1. Is this snippet correct?
doc = libxml2.parseDoc(readfile(filename))
ctxt = doc.xpathNewContext()
ctxt.xpathRegisterNs("xlink","http://www.w3.org/1999/xlink")

.... if so, to what purpose does one register the namespace
(xpathRegisterNs)???
It doesn't seem to effect the outcome of the script:
http://66.102.7.104/search?q=cache:s...hl=en&ie=UTF-8

....so I can't understand why it is being used.
2. Why do I seem to get unpredictable behaviour from code like:
doc = libxml2.parseFile("D:\\D\\XML\\system.xml")
current_nodes = doc.xpathEval("descendant-or-self::linux")
node = current_nodes[0]
print node
ctxt = node
while node:
node = node.xpathNextDescendant(node)
print node

How would I generate a list of all decendants of a node (besides
searching for children of children)?
3. Is there any such thing as an xlink ELEMENT (where element.ns =
"http://www.w3.org/1999/xlink")? The only examples that I can find only
demonstrate xlink ATTRIBUTES (where the namespace has to be declared in
every element with xlink attributes). I don't even know the reason for
declaring a namespace if we always do that.
Hopefuly someone can clear up my confusion.
Ben
Jul 20 '05 #1
1 2164
In article <20*******************@flowcom.com.au>,
<bd*****@flowcom.com.au> wrote:

% 1. Is this snippet correct?
% doc = libxml2.parseDoc(readfile(filename))
% ctxt = doc.xpathNewContext()
% ctxt.xpathRegisterNs("xlink","http://www.w3.org/1999/xlink")

It looks fine as far as it goes.

% ... if so, to what purpose does one register the namespace
% (xpathRegisterNs)???

It depends on what you're doing. If you want to match against an element
or attribute in the xlink name space, then you need to register the name
space and use the registered prefix in your searches. For instance, you
could look for

//*[@xlink:href]

to find all the elements with links from them. In the actual document,
the name space prefix could be different, so you could match

<note xl:href='http://www.somewhere.somewhat/etc/etc/etc'>...</note>

% ...so I can't understand why it is being used.

It might not be necessary.

% 3. Is there any such thing as an xlink ELEMENT (where element.ns =

There isn't, but why not read the overview and find out?
http://www.w3.org/TR/xlink

% demonstrate xlink ATTRIBUTES (where the namespace has to be declared in
% every element with xlink attributes). I don't even know the reason for

You might want to read up on name spaces, too. The key is to have the
name space declaration be in scope at the point the name space is
used. This doesn't require that it be declared in every element
that uses it, although some tools might handle it that way rather than
migrating the declaration up an element. Try adding the name space
declaration to the top-level element in your document tree.

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Juergen R. Plasser | last post by:
Hi, I have installed libxml2-2.5.7, libxslt-1.0.30 from source and the bindings libxml2-python-2.5.7. Everything seems to compile fine, but when I try to import the libxml2 library in python...
1
by: Victor Ng | last post by:
I've been trying to find information with how to figure out node identity in libxml2 - but I'm at a loss. I can't seem to find what I'm looking for on the xmlsoft.org site and google doesn't seem...
4
by: Kyle Root | last post by:
I'm writing a practice program that parses an xml config file, at the moment I'm using expat. However I don't like some of it's behaviors. For example ParseFile() will parse the *entire* file and...
0
by: Richard Taylor | last post by:
User-Agent: OSXnews 2.07 Xref: number1.nntp.dca.giganews.com comp.lang.python:437315 Hi I am trying to use py2app (http://undefined.org/python/) to package a gnome-python application...
2
by: corley | last post by:
Hello world, I am having a problem with the decimal symbol. The result of writing a floating-point-number to an xml document (using libxml2 from xmlsoft.org) is <number>10,1234</number> ...
1
by: cesar.ortiz | last post by:
Hi all, I have created an example using libxml2 based in the code that appears in http://xmlsoft.org/python.html. My example processes an enough amount of html files to see that the memory...
1
by: Andrew Marlow | last post by:
guys, I have been using libxml2 with python with no problems for just over a week but now I come to see if my script will work in someone else's environment and the libxml2 import fails. I am...
6
by: saumya.agarwal | last post by:
Hi, I am using libxml2 for xml parsing. When the client application sends data to libxml2 in UTF-8 format, it works fine. But, I have a scenarion in which the client application sends data to...
2
by: jianbing.chen | last post by:
Hi, I have this weird situation where on the same machine(solaris 8, python 2.5), one user can do this with no problem: <module 'libxml2' from '/usr/local/lib/python2.5/site-packages/...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.