It takes a while - and just when you think you've got it, another problem or
wierdness comes along.

:-)


Here's another Namespace wierdness that hit me a month or two ago...

    <bar xmlns="someUI">
        <car name="123">
    </bar>

Q: Whats the namespace URI of the <car>
A: someURI

Q: Whats the namespace of the @name attribute?
A: null - attributes do not inherit the default namespace.

James
----- Original Message -----
From: "Frank Sauer" <[EMAIL PROTECTED]>
To: "'James Strachan'" <[EMAIL PROTECTED]>
Cc: "jaxen-interest" <[EMAIL PROTECTED]>
Sent: Friday, September 21, 2001 7:49 PM
Subject: RE: [Jaxen] RE: some followup info


> OK, I think I'm beginning to get it finally...
> Still don't like it, but at least I understand
> the reasoning now.
>
> Frank
>
> -----Original Message-----
> From: James Strachan [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 21, 2001 2:34 PM
> To: Frank Sauer; Erwin Bolwidt
> Cc: jaxen-interest
> Subject: Re: [Jaxen] RE: some followup info
>
>
> Like Bob said, the prefixes used in the document and in the XPath
expression
> are irrelevent - what matters is the URI that the prefix maps to in the
> document and the URI that the prefix is mapped to in the XPath expression.
> The NamespaceContext in Jaxen defines what the namespace prefixes map to
in
> the XPath expression.
>
> So using "x" to map to "someURI" in NamespaceContext should be fine, even
if
> the namespace prefix is different in the document.
>
> James
> ----- Original Message -----
> From: "Frank Sauer" <[EMAIL PROTECTED]>
> To: "'James Strachan'" <[EMAIL PROTECTED]>; "Erwin Bolwidt"
> <[EMAIL PROTECTED]>
> Cc: "jaxen-interest" <[EMAIL PROTECTED]>
> Sent: Friday, September 21, 2001 7:32 PM
> 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
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com


_________________________________________________________
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

Reply via email to