wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes JDOM returns null exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JDOM returns null exception" Watch "JDOM returns null exception" New topic
Author

JDOM returns null exception

Veljko Cankovic
Greenhorn

Joined: Dec 27, 2011
Posts: 12
I have file in format below and want to have string field only with names of cities.

<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>
<GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
<GetCitiesByCountryResult><![CDATA[<NewDataSet>
<Table>
<Country>Finland</Country>
<City>Halli</City>
</Table>
<Table>
<Country>Finland</Country>
<City>Vaasa</City>
</Table>
</NewDataSet>]]></GetCitiesByCountryResult>
</GetCitiesByCountryResponse>
</soap:Body>
</soap:Envelope>


I must process it with Java. Everything is ok processed until NewDataSet tag which ruturns null always
erData is StructureData type


String citynames=" ";

Document erJdom = erData.getData();
Element root = erJdom.getRootElement();
Namespace erJdomNamespace = root.getNamespace();

Element item = root.getChild("GetCitiesByCountryResult", erJdomNamespace);
//(item.getText()) after thishere returns correct value everything works fine


//but from this I am getting null value:

Element newData1=item.getChild("NewDataSet",erJdomNamespace); //here is NULL


List tables = item.getChildren("TABLE");



for (int j = 0; j < tables.size(); j++)
{
erData.setAsCurrent(tables, j);



gradovi = gradovi + erData.getCurrentData("CITY");

}


William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
All of the text inside the <![CDATA[><NewDataSet> is NOT processed as XML but as a lump of text.

You would have to extract that text and parse it to a new DOM before you can use DOM methods on it.

I had a client that got stuck with a bunch of XML and code in that style - its a real pain to manipulate/edit/replace data inside a CDATA set as XML.

Bill
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
I would say it is very often and quite natural to deliver payload in a string which actually be the serialized xml document.

You can do it like this on a general plot. Replace this line:
>Element newData1=item.getChild("NewDataSet",erJdomNamespace); //here is NULL
by this block (with catching such as JDOMException on the way):

Then you are probably good to go ahead with it as what you've conceived therefrom.
Veljko Cankovic
Greenhorn

Joined: Dec 27, 2011
Posts: 12
Thanks William and g tsuji, you really helped me.
All the best!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDOM returns null exception
 
Similar Threads
unable to connect to .Net web service using axis with java
Response <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
how to set an attribute like SOAPAction in the Header?
web service client's frameworks handling of empty responces from web service
parsing doubt