Hi John

I see what you mean but could give me an example of a query with
local-name() ?
Thank you it is very interesting.

Regards,
Pascal

On Sat, Feb 23, 2008 at 11:21 AM, Psoroulas John <[EMAIL PROTECTED]>
wrote:

> Pascal,
>
> the xpath function "local-name()" is may the proper one for your purposes,
> take a look.
>
> Regards,
>
> John
>
>
>
> On Fri, February 22, 2008 21:14, Wing Yew Poon wrote:
> > Sorry, typo - the query should have been "declare default element
> > namespace 'mynamespace'; /a/b".
> >
> > ________________________________
> >
> >
> > From: Wing Yew Poon [mailto:[EMAIL PROTECTED]
> > Sent: Friday, February 22, 2008 11:11 AM
> > To: [email protected]
> > Subject: RE: Applying XPath to an XML with or without namespace
> >
> >
> >
> > Pascal,
> > in <a xmlns="mynamespace">
> > <b/>
> > </a>
> > what you have is every element within and including a being qualified as
> > having the namespace "mynamespace". Thus, the XPath must qualify the
> > elements too. This is only logical. There are a couple of ways you can
> > qualify the elements in the XPath. You can use the prolog you have in
> > "declare namespace xs='mynamespace';/xs:a/xs:b"; you can also use
> > "declare default namespace 'mynamespace; /a/b".
> > The bottom line is that the path must follow the structure of the
> > document. If elements/attributes are namespace-qualified in the
> document,
> > then they must be too in the path. - Wing Yew
> >
> >
> >
> > ________________________________
> >
> >
> > From: Pascal Maugeri [mailto:[EMAIL PROTECTED]
> > Sent: Friday, February 22, 2008 8:40 AM
> > To: [email protected]
> > Subject: Applying XPath to an XML with or without namespace
> >
> >
> >
> > Hi
> >
> >
> > I would like to have some clarifications on how to apply XPath query on
> > a XML document depending if it comes with or without a namespace
> > definition.
> >
> > When I run the following code executing the XPath query /a/b on a
> > document with no namespace:
> >
> > String doc = "<a><b/></a>";
> > String query = "/a/b";
> > XmlObject xml = XmlObject.Factory.parse(doc);
> > XmlCursor cursor = xml.newCursor();
> > cursor.push(); cursor.selectPath(query);
> >
> > it gives me the correct result (<c/>).
> >
> > But if if the document comes with a namespace, for instance:
> >
> >
> > <a xmlns="mynamespace">
> > <b/>
> > </a>
> >
> >
> > the same code does not give me any result.
> >
> > After investigating I found that a working code could be:
> >
> >
> > String doc = "<a xmlns="mynamespace"><b/></a>";
> > String query = "declare namespace xs='mynamespace';/xs:a/xs:b";
> > XmlObject xml = XmlObject.Factory.parse(doc);
> > XmlCursor cursor = xml.newCursor();
> > cursor.push(); cursor.selectPath(query);
> >
> > Is there a better way to do this without having to set the prefix "xs:"
> > in the Xpath query for each level ? I would like to find a generic way
> to
> > handle XML documents with or without namespace.
> >
> > Regards,
> > Pascal
> >
> >
> > Notice: This email message, together with any attachments, may contain
> > information of BEA Systems, Inc., its subsidiaries and affiliated
> entities,
> > that may be confidential, proprietary, copyrighted and/or legally
> > privileged, and is intended solely for the use of the individual or
> entity
> > named in this message. If you are not the intended recipient, and have
> > received this message in error, please immediately return this by email
> > and then delete it.
> >
> > Notice:  This email message, together with any attachments, may contain
> > information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> > entities,  that may be confidential,  proprietary,  copyrighted  and/or
> > legally privileged, and is intended solely for the use of the individual
> > or entity named in this message. If you are not the intended recipient,
> > and have received this message in error, please immediately return this
> > by email and then delete it.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to