You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Suzanne Dirkers <di...@us.ibm.com> on 2003/03/26 18:54:11 UTC

xpath expression




Hi Folks,


       I must be the least intuitive individual ever to work on trying to
work on xpath expressions. Once again it seems I have tried every which way
to use an xpath expression to try to get some information out of a file
using SimpleXPathAPI here, and wouldn't  you know, a lot of things that I
*think* should work according to examples in the Xpath work, don't.

        This is my xml file:
<?xml version="1.0"?>
<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:Body>
      <login xmlns="http://trade.com">
      <username>uid:xyz</username>
      <password>aaa
        </password>
      </login>
   </soap:Body>
</soap:Envelope>


  I found that ONLY /soap:Envelope/soap:Body would work as the context
node. I could NOT extend that path for the context node any farther than
'Body'.

   However, I did think this should work:  SimpleXPathAPI  mysoap.xml
soap:Envelope/soap:Body  ./login/username
The string value of the result is:
        (no result)


  Also tried:SimpleXPathAPI  mysoap.xml soap:Envelope/soap:Body
./*/username
The string value of the result is:
     (no result)


  SimpleXPathAPI  mysoap.xml soap:Envelope/soap:Body  .//username
The string value of the result is:
     (no result)

   SimpleXPathAPI  mysoap.xml soap:Envelope/soap:Body  child::username
     (no result)

  SimpleXPathAPI  mysoap.xml soap:Envelope/soap:Body   descendant::username
The string value of the result is:
     (no result)


  The ONLY!!!! thing I found that actually yielded a result was:
SimpleXPathAPI  mysoap.xml soap:Envelope/soap:Body   child::*
The string value of the result is:
           uid:0
           xxx

    From what I can tell , although 'username' is not prefixed by anything,
which to me means it should have no problem finding it, just like any
tagname on any xml element, and in my earlier posts I talked about being
able to find 'zipcode' in another xml file which also did not have a prefix
(and zipcode was found), 'username' here seems to be box office poison.
WHY??

      And, how do I get JUST the 'uid:0' back as a result?

Thanks,
Suzanne