Hpricot, namespaces, and TransactionResponse

3 views
Skip to first unread message

Micah

unread,
Dec 30, 2007, 7:39:51 PM12/30/07
to Remit
I'm getting some weirdness from the TransactionResponse, where all the
parameters of transaction_response (like transaction_id) are returning
nil.

Here's the XML that is returned:

<ns3:PayResponse
xmlns:ns3="http://fps.amazonaws.com/doc/
2007-01-08/"><ns3:TransactionResponse><TransactionId>12SM3VSFG1P43FK3NO8Q3I4CSMC5CKLXXXX</
TransactionId><Status>Initiated</
Status><NewSenderTokenUsage><Amount><CurrencyCode>USD</
CurrencyCode><Amount>5.000000</Amount></
Amount><LastResetAmount><CurrencyCode>USD</CurrencyCode><Amount>0</
Amount></LastResetAmount></NewSenderTokenUsage></
ns3:TransactionResponse><Status>Success</
Status><RequestId>71c3b0fc-4965-479a-87ec-39a447XXXX7b:0</RequestId></
ns3:PayResponse>


I've been scratching my head over this one, and I can't figure
anything
out. Could it have anything to do with the ns3 namespace on the
TransactionResponse element? I
thought I read somewhere that Hpricot doesn't do so well with
namespaces, but this is the first time I've had this problem with
Remit.

Any thoughts?
Micah

P.S. Sorry if this is a double-post. I didn't see it appear the first
time I sent the e-mail.

Micah

unread,
Dec 30, 2007, 8:04:41 PM12/30/07
to Remit
I've looked a little more into this, and it does seem to be an issue
with the namespaces. As far as I can tell, PayResponse is the only
API call that I've used so far that uses namespaces anywhere except
for the root node.

Glancing at Response in Relax, I noticed that the is? method seems to
throw away the namespace, and that's the only method that deals with
namespaces at all.

From a general-purpose REST wrapper, I think being namespace ignorant
could be a major deficiency. For me, I'm more worried about the
ramifications for Remit in particular.

I've read a little on Hpricot, and it seems that its XPath searching
cannot handle namespaces, mainly because it was designed with HTML
parsing in mind, not XML. The underlying parser just treats them as
different elements. So xml.at("ns3:TransactionResponse") will get me
what I want, but xml.at("TransactionResponse") will always get me
nil. Plus, I'm not sure how the namespaces are chosen/assigned, so I
don't know for sure if it will always be "ns3" or if it changes.

Seeing as how this is an underlying deficiency of Hpricot and not
Relax, my first inclination would be to suggest ripping out Hpricot
and replacing it with REXML. It might not be as fast, but I'm fairly
certain it can handle namespaces (although not 100%). Further, Relax
looks very well encapsulated so that replacing Hpricot with REXML
would be a small, localized change that would not propagate out into
Remit or other code.

I'll futz around with the Hpricot based code for a while longer, but
if I can't make headway soon, I'll see what it would take to use
REXML.

Micah

Micah

unread,
Dec 31, 2007, 10:13:23 AM12/31/07
to Remit
Looks like they're planning on using ns3 exclusively:
http://developer.amazonwebservices.com/connect/thread.jspa?messageID=69340

Micah

Micah

unread,
Dec 31, 2007, 11:03:42 AM12/31/07
to Remit
I tried specifying

:element => "ns3:TransactionResponse"

in the Remit::Pay::Reponse class in pay.rb, but that doesn't seem to
work. I'm guessing that Hpricot does not like colons in XPath
queries. For example, given the following XML:

<ns3:PayResponse
xmlns:ns3="http://fps.amazonaws.com/doc/
2007-01-08/"><ns3:TransactionResponse><TransactionId>12SM3VSFG1P43FK3NO8Q3I4CSMC5CKLXXXX</
TransactionId><Status>Initiated</
Status><NewSenderTokenUsage><Amount><CurrencyCode>USD</
CurrencyCode><Amount>5.000000</Amount></
Amount><LastResetAmount><CurrencyCode>USD</CurrencyCode><Amount>0</
Amount></LastResetAmount></NewSenderTokenUsage></
ns3:TransactionResponse><Status>Success</
Status><RequestId>71c3b0fc-4965-479a-87ec-39a447XXXX7b:0</RequestId></
ns3:PayResponse>

and assuming that X is an Hpricot::Doc

x.root.at("/Status") gives the <Status>Success</Status> element, and
x.root.at("/RequestId") also gives the correct element.

however,
x.root.at("/ns3:TransactionResponse") gives nil, as does x.root.at("/
TransactionResponse")

For now, I'm giving up. I'll just work on the raw XML that's in the
response in order to get the transaction ID.

Micah

On Dec 31, 10:13 am, Micah <fanm...@micah-wedemeyer.net> wrote:
> Looks like they're planning on using ns3 exclusively:http://developer.amazonwebservices.com/connect/thread.jspa?messageID=...

Tyler Hunt

unread,
Dec 31, 2007, 11:23:33 AM12/31/07
to re...@googlegroups.com
On Dec 31, 2007, at 11:03 AM, Micah wrote:

> and assuming that X is an Hpricot::Doc
>
> x.root.at("/Status") gives the <Status>Success</Status> element, and
> x.root.at("/RequestId") also gives the correct element.
>
> however,
> x.root.at("/ns3:TransactionResponse") gives nil, as does x.root.at("/
> TransactionResponse")

According to why:

"Hpricot doesn’t have problems parsing namespaces, however its xpath
syntax doesn’t support namespaces since its a hybrid of CSS and XPath."

However, I also found this so I'm not really sure what the current
support is:

http://code.whytheluckystiff.net/hpricot/changeset/99

Reply all
Reply to author
Forward
0 new messages