Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Seek XPath Expression

Question posted by: gimme_this_gimme_that@yahoo.com (Guest) on June 27th, 2008 07:07 PM
This may be so easy no one responds.

What is the XPath expression that fetches the value PPV - the
PersistentTicket?

The namespace thing is throwing me off.

Thanks.

<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/
XMLSchema"><soap:Header><CompanyAuthHeader xmlns="http://
webservices.monster.com/MonsterPortal"><PersistentTicket>PPV</
PersistentTicket>
</CompanyAuthHeader>
</soap:Header>
<soap:Body>
<AuthenticateByCompanyAccessTicketResponse xmlns="http://ws.com/VX">
<AuthenticateByCompanyAccessTicketResult>true</
AuthenticateByCompanyAccessTicketResult>
</AuthenticateByCompanyAccessTicketResponse>
</soap:Body>
</soap:Envelope>

Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
pr's Avatar
pr
Guest
n/a Posts
June 27th, 2008
07:07 PM
#2

Re: Seek XPath Expression
Join Bytes! wrote:
Quote:
Originally Posted by
This may be so easy no one responds.
>
What is the XPath expression that fetches the value PPV - the
PersistentTicket?
>
The namespace thing is throwing me off.
>
Thanks.
>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/
XMLSchema"><soap:Header><CompanyAuthHeader xmlns="http://
webservices.monster.com/MonsterPortal"><PersistentTicket>PPV</
PersistentTicket>
</CompanyAuthHeader>
</soap:Header>
<soap:Body>
<AuthenticateByCompanyAccessTicketResponse xmlns="http://ws.com/VX">
<AuthenticateByCompanyAccessTicketResult>true</
AuthenticateByCompanyAccessTicketResult>
</AuthenticateByCompanyAccessTicketResponse>
</soap:Body>
</soap:Envelope>
>


The most efficient would be:

/soap:Envelope/soap:Header/
monster:CompanyAuthHeader/monster:PersistentTicket/text()

where you have declared (by whatever means appropriate in the tool
you're using)

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:monster="http://webservices.monster.com/MonsterPortal"


You could also do:

//monster:PersistentTicket/text()

or (without declaring the namespaces):

//*[local-name() = 'PersistentTicket' and namespace::node()[. =
'http://webservices.monster.com/MonsterPortal']]/text()

pr's Avatar
pr
Guest
n/a Posts
June 27th, 2008
07:07 PM
#3

Re: Seek XPath Expression
pr wrote:
Quote:
Originally Posted by
//*[local-name() = 'PersistentTicket' and namespace::node()[. =
'http://webservices.monster.com/MonsterPortal']]/text()


Sorry. Should be:

//*[local-name() = 'PersistentTicket' and namespace-uri() =
'http://webservices.monster.com/MonsterPortal']/text()

gimme_this_gimme_that@yahoo.com's Avatar
gimme_this_gimme_that@yahoo.com
Guest
n/a Posts
June 27th, 2008
07:07 PM
#4

Re: Seek XPath Expression
On Jun 12, 4:27*am, pr <p...@porl.globalnet.co.ukwrote:
Quote:
Originally Posted by
pr wrote:
Quote:
Originally Posted by
* //*[local-name() = 'PersistentTicket' and namespace::node()[. =
* * 'http://webservices.monster.com/MonsterPortal']]/text()

>
Sorry. Should be:
>
* *//*[local-name() = 'PersistentTicket' and namespace-uri() =
* * *'http://webservices.monster.com/MonsterPortal']/text()


This worked perfectly. Thanks Pr.

I'm using Java (org.jdom.xpath.XPath) which has the following method:

addNamespace(java.lang.String prefix, java.lang.String uri)
which adds a namespace definition (prefix and URI) to the list of
namespaces known of this XPath expression.

My this case, what are the values of prefix and uri?

Thanks.



pr's Avatar
pr
Guest
n/a Posts
June 27th, 2008
07:07 PM
#5

Re: Seek XPath Expression
Join Bytes! wrote:
Quote:
Originally Posted by
I'm using Java (org.jdom.xpath.XPath) which has the following method:
>
addNamespace(java.lang.String prefix, java.lang.String uri)
which adds a namespace definition (prefix and URI) to the list of
namespaces known of this XPath expression.
>
My this case, what are the values of prefix and uri?


The prefix is up to you, provided you don't repeat a prefix already used
in your document (e.g. 'soap'), start the prefix with a letter or
underscore, and confine yourself to the characters

A-Z a-z 0-9 _ - .

(or consult <URL: http://www.w3.org/TR/xml-namesfor the full range of
permissible characters, software permitting).

Without knowing Java in any detail, I presume

addNamespace("monster",
"http://webservices.monster.com/MonsterPortal")

is appropriate if you want to use

monster:PersistentTicket

in your XPath, and

addNamespace("m", "http://webservices.monster.com/MonsterPortal")

if you want to use

m:PersistentTicket

The significant thing about the namespace is its URI - you could add the
namespace twice and use the prefixes interchangeably, although that
might be unnecessarily confusing :-)

 
Not the answer you were looking for? Post your question . . .
182,081 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors