Seek XPath Expression

Discussion in 'XML' started by gimme_this_gimme_that@yahoo.com, Jun 12, 2008.

  1. Guest

    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>
    , Jun 12, 2008
    #1
    1. Advertising

  2. pr Guest

    wrote:
    > 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, Jun 12, 2008
    #2
    1. Advertising

  3. pr Guest

    pr wrote:
    > //*[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()
    pr, Jun 12, 2008
    #3
  4. Guest

    On Jun 12, 4:27 am, pr <> wrote:
    > pr wrote:
    > >   //*[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.
    , Jun 13, 2008
    #4
  5. pr Guest

    wrote:
    > 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 :)
    pr, Jun 13, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,968
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,399
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    520
  4. GIMME
    Replies:
    3
    Views:
    11,948
    vforvikash
    Dec 29, 2008
  5. Replies:
    3
    Views:
    127
    Andreas Perstinger
    May 14, 2013
Loading...

Share This Page