Re: [libxml++] Searching nodes with ns prefix
- From: Darko Miletic <darko uvcms com>
- To: togol machillan <togolmach2 lycos com>
- Cc: libxmlplusplus-general lists sourceforge net
- Subject: Re: [libxml++] Searching nodes with ns prefix
- Date: Sun, 16 Oct 2005 14:38:34 -0300
togol machillan wrote:
Dear Members,
I am facing the problem of finding nodes in an OWL file. The importance of registering the namespace before calling the find() function has been discussed before, but still the find function in libxml++ v2.12 does not support this. I defined a new function as follows.
The "undefined namespace prefix" error message does not appear anymore, but the node set is still empty. I call the find() function for the root node rdf:RDF of the owl document with the XPath expr //owl:Ontology. If I add a check to see whether the OWL namespace is already registered using xmlSearchNs(), it returns the namespace pointer since for OWL, the namespace is always defined in the root node.
Can somebody please point out where the problem is?
Namespace needs to be registered ONLY if it is default namespace. Other
namespaces are recognized properly. That means if you have xml file like
this:
<?xml version="1.0" encoding="UTF-8"?>
<rootitem xmlns="http://www.something.com/ns1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.something.com/ns1 ns1.xsd"
version="1.3">
In this case you must register ns1.xsd before doing find. For example
like this:
xmlXPathRegisterNs( ctxt,
"ns1",
"http://www.something.com/ns1");
The when doing search you should prefix all nodes from default namespace
with namespace name you registered:
node->find("//ns1:rootitem/otheritem");
Not placing registered prefix for default namespace in xpath string is
the most common error when using libxml++ or libxml2.
Darko
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]