John,
JXPath 1.2 handles namespaces somewhat differently from JXPath 1.1. It is
following the XPath specification more closely. The specification describes
the procedure of matching a name by comparing so-called expanded names. An
expanded name is a combination of a local name and a namespace URI. In your
particular case, the LDAP element in the document has the expanded name
("LDAP", "http://www.verticon.com/react2/schema"), while the "LDAP" node
test expands to ("LDAP", null).
Quote from the spec: "Two expanded-names are equal if they have the same
local part, and either both have a null namespace URI or both have non-null
namespace URIs that are equal."
The notion of default namespace applies to elements of an XML document, but
does not apply to XPaths. Quote: "if the QName does not have a prefix, then
the namespace URI is null (this is the same way attribute names are
expanded). It is an error if the QName has a prefix for which there is no
namespace declaration in the expression context [i.e. JXPathContext]."
To remedy the situation, do the following two things:
1. Register the namespace with the JXPathContext:
context.registerNamespace("schema",
"http://www.verticon.com/react2/schema");
2. Use this prefix in your XPaths:
context.getValue("//schema:LDAP")
I hope this helps,
- Dmitri
----- Original Message -----
From: "John E. Conlon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 11, 2004 5:20 PM
Subject: [jxpath] Namespace problem with 1.2
> Have been using version 1.1 to manipulate XML documents using a default
> namespace without any problems, but 1.2 doesn't work with my code.
>
> Here is a sample document:
>
> <?xml version = "1.0" encoding = "UTF-8"?>
> <Configuration xmlns = "http://www.verticon.com/react2/schema">
> <URIObjectSource>
> <LDAP>
> <URIObjectDefinition implementation="flagpools"/>
> </LDAP>
> </URIObjectSource>
> </Configuration>
>
> With JXPath 1.1 I could use the a XPath "//LDAP" to get to the LDAP node
> of this document, but with 1.2 I cannot.
>
> For example:
> JXPathContext context = JXPathContext.newContext(myDocument);
> Object o = context.getValue("//LDAP");
>
> JXPath 1.1 will return a value but 1.2 returns a null.
>
> Any ideas how I can get 1.2 working?
>
> John Conlon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]