B
bdecker
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:...0/weblog/2004/Jan+xlink+python&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
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:...0/weblog/2004/Jan+xlink+python&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