Seek XPath Expression

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

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>
 
P

pr

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()
 
G

gimme_this_gimme_that

pr said:
  //*[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.
 
P

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?

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-names> for 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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top