[jdom-interest] Namespace problem
Frank Cohen
fcohen at pushtotest.com
Thu Jul 18 14:04:00 PDT 2002
I'm having a problem using the Element.getChild() method when the
element uses a namespace with no prefix. The getChild() method seems to
always return a null value. The XML document is a response to a SOAP
request. I'm using Jython (the Java implementation of Python):
builder = SAXBuilder()
doc = builder.build( StringReader( response.toString() ) )
envelopeElement = doc.getRootElement()
soap_ns = Namespace.getNamespace
("soap", "http://schemas.xmlsoap.org/soap/envelope/")
bodyElement = envelopeElement.getChild("Body", soap_ns)
so_ns = Namespace.getNamespace( "", "http://www.serviceobjects.com")
at this point in the script I try to get the child using:
atmrespElement = bodyElement.getChild( "GetATMLocationsResponse",
so_ns )
this returns null.
I try another technique by using getChildre():
print "Body Children"
bc = bodyElement.getChildren()
for i in bc:
print i, i.getNamespace()
and this works. The i.getNamespace() returns:
[Element: <GetATMLocationsResponse [Namespace:
http://www.serviceobjects.com/]/>] [Namespace: prefix "" is mapped to
URI "http://www.serviceobjects.com/"]
Below is the XML document.
Any help would be appreciated.
Thanks.
-Frank
<?xml version="1.0" encoding="utf-8"?><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><GetATMLocations
Response
xmlns="http://www.serviceobjects.com/"><GetATMLocationsResult><ATM><Bank
>BAHAR MARKET</Bank><Address>811 W. HAMILTON
AV</Address><Location>N/A</Location><City>CAMPBELL</City><State>CA</Stat
e><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545</Longi
tude><Notes>24-Hour Access</Notes></ATM><ATM><Bank>BANK OF
AMERICA</Bank><Address>1875 S BASCOM AVE STE</Address><Location>THE
PRUNEYARD
OP</Location><City>CAMPBELL</City><State>CA</State><Zip>95008</Zip><Lati
tude>37.2788</Latitude><Longitude>121.9545</Longitude><Notes>24-Hour
Access</Notes></ATM><ATM><Bank>BANK OF AMERICA</Bank><Address>200 THE
PRUNEYARD</Address><Location>THE
PRUNEYARD</Location><City>CAMPBELL</City><State>CA</State><Zip>95008</Zi
p><Latitude>37.2788</Latitude><Longitude>121.9545</Longitude><Notes>24-
Hour Access</Notes></ATM><ATM><Bank>CHASEWOOD BANK</Bank><Address>1859
BUCKNALL ROAD</Address><Location>LIQUOR & FOOD
MART</Location><City>CAMPBELL</City><State>CA</State><Zip>95008</Zip><La
titude>37.2788</Latitude><Longitude>121.9545</Longitude><Notes>24-Hour
Access</Notes></ATM><ATM><Bank>DOWNEY SAVINGS</Bank><Address>1480 W.
CAMPBELL
AVE.</Address><Location>N/A</Location><City>CAMPBELL</City><State>CA</St
ate><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545</Lon
gitude><Notes>24-Hour Access</Notes></ATM><ATM><Bank>EDS/7-11 SAN
FRANCISCO/SACRAMENTO</Bank><Address>262 W.SUNNY
OAKS</Address><Location>N/A</Location><City>CAMPBELL</City><State>CA</St
ate><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545</Lon
gitude><Notes>24-Hour
Access</Notes></ATM><ATM><Bank>EUREKABANK</Bank><Address>750 WEST
HAMILTON
AVENUE</Address><Location>N/A</Location><City>CAMPBELL</City><State>CA</
State><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545</L
ongitude><Notes>24-Hour Access</Notes></ATM><ATM><Bank>FIRST BANK &
TRUST</Bank><Address>790 E CAMPBELL
AVE</Address><Location>N/A</Location><City>CAMPBELL</City><State>CA</Sta
te><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545</Long
itude><Notes>24-Hour Access</Notes></ATM><ATM><Bank>SAFEAMERICA FEDERAL
CREDIT UNION</Bank><Address>1530 HAMILTON
AVE.</Address><Location>SAFEWAY</Location><City>CAMPBELL</City><State>CA
</State><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545<
/Longitude><Notes>24-Hour Access</Notes></ATM><ATM><Bank>TAQUERIA
LOS</Bank><Address>1581 W
CAMPBELL</Address><Location>N/A</Location><City>CAMPBELL</City><State>CA
</State><Zip>95008</Zip><Latitude>37.2788</Latitude><Longitude>121.9545<
/Longitude><Notes>24-Hour
Access</Notes></ATM></GetATMLocationsResult></GetATMLocationsResponse></
soap:Body></soap:Envelope>
--
http://www.PushToTest.com for free testing tools for testing Web
Services
More information about the jdom-interest
mailing list