In article <>,
<> 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