Eg:

  XPath theBs = new XPath("//x:bbb");
  theBs.addNamespace("x", http://localhost:8080);

  Element b = (Element)theBx.selectSingleNode(myDoc);

Note that the element in the original document does not have to be prefixed
with an "x", nor does the prefix in the code above have to be "x" - the
XPath namespace is arbitrary, it just needs to be there so that Jaxen can
tell which element you're after.

Cheers,

David

----- Original Message -----
From: "Elliotte Rusty Harold" <[EMAIL PROTECTED]>
To: "Supriyo Chatterjea" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Friday, August 09, 2002 12:13 AM
Subject: Re: [Jaxen] JDOMDemo doesn't run with Namespace


> At 9:35 PM +0800 8/8/02, Supriyo Chatterjea wrote:
>
>
> ><aaa>
> >   <bbb xmlns="http://localhost:8080";>
> >     <ccc TTL="10000" ID="12E">
> >       <ddd No="12"/>
> >     </ccc>
> >   </bbb>
> ></aaa>
> >
> >This is my query statement: //bbb
> >The result is empty.
> >
> >However, when I remove the namespace, I get the
> >element <bbb>. What do I need to do to get the program
> >to return the element <bbb> when the source file has
> >the namespace in it?
> >
>
> You need to use a prefix in your XPath statement and map that prefix
> to the namespace URI http://localhost:8080
> --
>
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | [EMAIL PROTECTED] | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> |          XML in a  Nutshell, 2nd Edition (O'Reilly, 2002)          |
> |              http://www.cafeconleche.org/books/xian2/              |
> |  http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/  |
> +----------------------------------+---------------------------------+
> |  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
> |  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
> +----------------------------------+---------------------------------+
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Jaxen-interest mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jaxen-interest



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to