oops, previous mail wasn't finished, but I lost that train of thought.
Sorry.
please ignore last sentence.

Frank Sauer
The Technical Resource Connection, Inc.
a wholly owned subsidiary of Perot Systems
Tampa, FL
http://www.trcinc.com
-----------------------------------------------
Java: The best argument for Smalltalk since C++


-----Original Message-----
From: Frank Sauer [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 21, 2001 2:32 PM
To: 'James Strachan'; Erwin Bolwidt
Cc: jaxen-interest
Subject: RE: [Jaxen] RE: some followup info


But that's still not going to work because the xml elements
don't have the prefix. So even if I add
a mapping from x to "http://.......";, the XML contains this
stupid xmlns="http://....."; as a #FIXED attribute declared in
an offical J2EE DTD..... So the elements don't use a prefix.
I printed the prefix and URI for the Namespace object I get from
JDOM in this attempt to solve the problem:

private String eval(Element context, String expr) {
   try {   
     XPath xpath = new XPath( expr );    
     Namespace ns = context.getNamespace();
     if ((ns != null) && (ns != Namespace.NO_NAMESPACE)) {
        SimpleNamespaceContext nsc = new SimpleNamespaceContext();   
        System.err.println("Setting NamespaceContext for " + ns.getPrefix()
+ " to " + ns.getURI());
        nsc.addNamespace(ns.getPrefix(), ns.getURI());
        xpath.setNamespaceContext(nsc);
     }
     List results = xpath.selectNodes( context );  

But you're right, now the functions don't resolve...:

Setting NamespaceContext for  to
http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd
org.jaxen.UnresolvableException: Function :concat
        at
org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:43)
        at org.jaxen.ContextSupport.getFunction(ContextSupport.java:114)
        at org.jaxen.Context.getFunction(Context.java:67)
        at
org.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java
:122)
        at org.jaxen.expr.DefaultXPath.asList(DefaultXPath.java:46)
        at org.jaxen.JaXPath.jaSelectNodes(JaXPath.java:35)
        at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:22)
        at
com.trcinc.xmltalk.xml.dtd.DTDCatalog$CatalogEntry.eval(DTDCatalog.java:150)


By the way, I thought I saw in earlier versions of Jaxen an
addNamespaceContext so
Frank Sauer
The Technical Resource Connection, Inc.
a wholly owned subsidiary of Perot Systems
Tampa, FL
http://www.trcinc.com
-----------------------------------------------
Java: The best argument for Smalltalk since C++


-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 21, 2001 11:16 AM
To: Erwin Bolwidt
Cc: Frank Sauer; 'bob mcwhirter'; jaxen-interest
Subject: Re: [Jaxen] RE: some followup info


From: "Erwin Bolwidt" <[EMAIL PROTECTED]>
> On Fri, 21 Sep 2001, James Strachan wrote:
>
> > You can bind the empty prefix to a namespace URI. Its often called the
> > 'default namespace'.
> >
> > e.g.
> >
> > <foo xmlns="someURI">
> >     <bar/>
> > </foo>
> >
> > In the above document the XPath expression /foo/bar will not work unless
you
> > explicitly setup a NamespaceContext to set the default namespace URI to
be
> > "someURI". If you map empty prefix, "", to "someURI" in your
> > NamespaceContext then /foo/bar will work.
>
> That would have been convenient if it were possible, but there are two
> problems:
>
> * xpath explicitly disallows it, in section 2.3:
> "A QName in the node test is expanded into an expanded-name using the
> namespace declarations from the expression context. This is the same way
> expansion is done for element type names in start and end-tags except
> that the default namespace declared with xmlns is not used: 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."
>
> * a practical one: functions and variables are also qualified names; if
> you were to rebind the empty prefix to some namespace, then you wouldn't
> be able to call any of the built-in xpath functions, since they have no
> namespace URI. Jaxen simply won't be able to find the functions or
> variables.

Ah OK. Thats a huge shame but I guess to work with non-namespaced functions
and variables it has to be like that.

Thanks for clearing that up - I stand corrected. The only way to properly
evaluate that XPath expression is then this ugly huge thing...

/*[local-name()='foo' and namespace-uri()='someURI']//*[local-name()='bar'
and namespace-uri()='someURI']/

Though I suppose you could map your own new prefix to the URI instead. So
rather than mapping "" to "someURI" you could map "x" to "someURI" and then
do

/x:foo/x:bar

which should work.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to