+ Reply to Thread
Results 1 to 4 of 4

Thread: dekiscript and xpath

  1. #1

    Default dekiscript and xpath

    Hello,

    I've noticed that when using web.text and an xpath query only the first result of the xpath query is returned.
    Is there anyway to return a list of the entire result set? For example the following query against this feed (http://www.govtrack.us/data/us/108/bills/h107.xml) should return all 26 id attributes for <cosponsors> tag.

    XPATH QUERY :
    //cosponsors/cosponsor/@id


    But when combining it with web.text it only prints out the first result: 400001

    web.text('http://www.govtrack.us/data/us/108/bills/h107.xml', '//cosponsors/cosponsor/@id')

    Any suggestions?

    Thanks,
    Ilan

  2. #2
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    I'm working on adding web.list, which will return a list of strings for a given xpath, but currently it's not possible unless you use an explicit index in the xpath expression.

    For example: //cosponsors/cosponsor[15]/@id
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  3. #3

    Default

    Steve, thanks for the reply.

    Originally what I was trying to do is find out if a specific ID existed in a feed. So //cosponsors/cosponsor[@id=40001]. However, I wasn't sure how to check for that as web.text with that xpath query would return a blank string as the tag has no contents, just an attribute.

    I was going for the list, as I thought it might be easier to get a full list of tags and do a string match against the list. Would web.list be the way to go in the future?

    A 2nd way I thought about doing this was using a eval:if with the test being the xpath. I'm not sure if that would work though and will likely try it in the morning.

    Thank you for all of your help!
    -Ilan

  4. #4
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    This xpath would work: //cosponsors/cosponsor[@id=40001]/@id

    It's a bit weird, but does the trick. It looks for a cosonsor element with id=40001 and then, if it finds it, returns the value of the id.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts