File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JDOM returns null exception" Watch "JDOM returns null exception" New topic

JDOM returns null exception

Veljko Cankovic

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="" xmlns:xsi="" xmlns:xsd="">
<GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">

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

Joined: Mar 22, 2000
Posts: 13024
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.

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 617
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

Joined: Dec 27, 2011
Posts: 12
Thanks William and g tsuji, you really helped me.
All the best!
I agree. Here's the link:
subject: JDOM returns null exception
It's not a secret anymore!