Hi,

Can you give this a try?

e = REXML::Document.new(ie.text).root.elements
e["/tokens/ShortUrl[starts-with(@url,
"resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada"].attributes["url"]


As you already know value of 'm' in query string you can create a string a
give it a try.

- Angrez




On 5/11/07, Zeljko <[EMAIL PROTECTED]> wrote:

I have xml that looks like this.

<tokens>
  <ShortUrl 
url="resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada&amp;code=2271ad0e-d627-4e6c-bdfb-2b11d354e9ac"
hash="BF8E8F60E722E92C7ED8303916591AB4" />
</tokens>

I need to get value of "hash" attribute
(BF8E8F60E722E92C7ED8303916591AB4). I know the value of "m" url parameter
(inside "url" attribute) (7fb83717-9606-4022-bd4e-67b6f6582ada), but I do
not know the value of "code" url parameter.

I know how to get attribute of a tag when I know another attribute of that
tag. For example, if I knew "hash" attribute and needed "url" attribute, I
would do it like this:

e = REXML::Document.new (ie.text).root.elements

e["/tokens/[EMAIL 
PROTECTED]'BF8E8F60E722E92C7ED8303916591AB4']"].attributes["url"]
=> 
"resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada&code=2271ad0e-d627-4e6c-bdfb-2b11d354e9ac"


But, I know only part of "url" attribute. Of course, this does not work
(because e[...] returns nil).

e["/tokens/[EMAIL 
PROTECTED]'resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada&code=']"].attributes["hash"]

=> NoMethodError: undefined method `attributes' for nil:NilClass

I have heard that there are xpath string functions 
(http://www.w3.org/TR/xpath#section-String-Functions
), but I did not understand how to use them, or would it even help in this
case.

I have solved this problem with regular expressions, but I guess there
must be xpath solution.

Also, I have already asked my developer to simplify that xml, so I can use
it, but that has low priority because I have already solved the problem.

Does anybody know how to do this using xpath?

Zeljko
--
ZeljkoFilipin.com
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to