Xml parsing from string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Xml parsing from string

cjhowe
In the Google Checkout integration, I'm needing to parse the following
xml string...

<?xml version="1.0" encoding="UTF-8"?><checkout-redirect
xmlns="http://checkout.google.com/schema/2"
serial-number="ec09382f-c1b3-4ab2-8090-35906e3918e6">  
<redirect-url>
https://sandbox.google.com/checkout/view/buy?o=shoppingcart&amp;shoppingcart=dgfi89u2398
</redirect-url>
</checkout-redirect>

I have it contained as a string.  How do I get the value of the
redirect-url
(https://sandbox.google.com/checkout/view/buy?o=shoppingcart&amp;shoppingcart=dgfi89u2398)?


I've tried the following:
=============
response = <?xml version ... (from above)
document = org.ofbiz.base.util.UtilXml.readXmlDocument(response);
rootElement = document.getRootElement;
childList = org.ofbiz.base.util.UtilXml.childElementList(rootElement);
childListIter = childList.iterator();
while (childListIter.hasNext()){
   child = childListIter.next();
   nodeName = child.getNodeName();
   if ("call-map-processor".equals(nodeName)){
      redirect = org.ofbiz.base.util.UtilXml.elementValue(child);
   }

==============

document ends up returning [#document: null]

any ideas would greatly be appreciated.  Thanks!
-Chris
Reply | Threaded
Open this post in threaded view
|

Re: Xml parsing from string

Andrew Sykes
FlexibleLocation perhaps?

That's just a guess and from memory though ;-)

- Andrew

On Tue, 2007-02-06 at 07:40 -0800, Chris Howe wrote:

> In the Google Checkout integration, I'm needing to parse the following
> xml string...
>
> <?xml version="1.0" encoding="UTF-8"?><checkout-redirect
> xmlns="http://checkout.google.com/schema/2"
> serial-number="ec09382f-c1b3-4ab2-8090-35906e3918e6">  
> <redirect-url>
> https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=dgfi89u2398
> </redirect-url>
> </checkout-redirect>
>
> I have it contained as a string.  How do I get the value of the
> redirect-url
> (https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=dgfi89u2398)?
>
>
> I've tried the following:
> =============
> response = <?xml version ... (from above)
> document = org.ofbiz.base.util.UtilXml.readXmlDocument(response);
> rootElement = document.getRootElement;
> childList = org.ofbiz.base.util.UtilXml.childElementList(rootElement);
> childListIter = childList.iterator();
> while (childListIter.hasNext()){
>    child = childListIter.next();
>    nodeName = child.getNodeName();
>    if ("call-map-processor".equals(nodeName)){
>       redirect = org.ofbiz.base.util.UtilXml.elementValue(child);
>    }
>
> ==============
>
> document ends up returning [#document: null]
>
> any ideas would greatly be appreciated.  Thanks!
> -Chris
--
Kind Regards
Andrew Sykes <[hidden email]>
Sykes Development Ltd
http://www.sykesdevelopment.com

Reply | Threaded
Open this post in threaded view
|

Re: Xml parsing from string

cjhowe
Andrew,

Thanks for the response.  It ended up being that I didn't change my
copy and paste :-)

if ("call-map-processor".equals(nodeName)){

should have been:

if ("redirect-url".equals(nodeName)){



--- Andrew Sykes <[hidden email]> wrote:

> FlexibleLocation perhaps?
>
> That's just a guess and from memory though ;-)
>
> - Andrew
>
> On Tue, 2007-02-06 at 07:40 -0800, Chris Howe wrote:
> > In the Google Checkout integration, I'm needing to parse the
> following
> > xml string...
> >
> > <?xml version="1.0" encoding="UTF-8"?><checkout-redirect
> > xmlns="http://checkout.google.com/schema/2"
> > serial-number="ec09382f-c1b3-4ab2-8090-35906e3918e6">  
> > <redirect-url>
> >
>
https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=dgfi89u2398
> > </redirect-url>
> > </checkout-redirect>
> >
> > I have it contained as a string.  How do I get the value of the
> > redirect-url
> >
>
(https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=dgfi89u2398)?

> >
> >
> > I've tried the following:
> > =============
> > response = <?xml version ... (from above)
> > document = org.ofbiz.base.util.UtilXml.readXmlDocument(response);
> > rootElement = document.getRootElement;
> > childList =
> org.ofbiz.base.util.UtilXml.childElementList(rootElement);
> > childListIter = childList.iterator();
> > while (childListIter.hasNext()){
> >    child = childListIter.next();
> >    nodeName = child.getNodeName();
> >    if ("call-map-processor".equals(nodeName)){
> >       redirect = org.ofbiz.base.util.UtilXml.elementValue(child);
> >    }
> >
> > ==============
> >
> > document ends up returning [#document: null]
> >
> > any ideas would greatly be appreciated.  Thanks!
> > -Chris
> --
> Kind Regards
> Andrew Sykes <[hidden email]>
> Sykes Development Ltd
> http://www.sykesdevelopment.com
>
>