File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to handle this kind of XML 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 "How to handle this kind of XML" Watch "How to handle this kind of XML" New topic
Author

How to handle this kind of XML

Robin Dee
Greenhorn

Joined: Mar 25, 2010
Posts: 7
Hello all,

I'm fairly new to Java; since a few days I've been playing around with Java, XML and SOAP. With some aid of Eclipse I've written a client for a SOAP webservice, using Axis.

The webservice I need to access anwers in a somewhat odd way: the body of the SOAP response features a CDATA block, containing another XML document with the requested data. I can handle that, so no questions there.

However... I need to process the information in the SOAP response. Because of the document layout I don't know how to do that in an efficient way.

XML example:


As you might have noticed, the document above contains information on a customer and products somehow related to this customer. Put differently: there's a one-to-many relationship hidden in this document.

So here's the question: how to handle this in an efficient way, given I want to do things like listing all the products for a customer..? Should I put the relevant information from the XML document in some other data container first (multidimensional array?)?

The actual XML document as returned by the SOAP service is rather large and may contain quite a few of these constructions.

Thanks in advance!

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You cannot directly process the XML-based data from a Java application. First you need to read the data and extract the data that is relevant to what you want and then populate one or more Java data objects with this data. Once this data is in object form, you can then do whatever you want with it. There are many, many different way to get the data from XML-based format to object-oriented format and then to relational table format.
Robin Dee
Greenhorn

Joined: Mar 25, 2010
Posts: 7
Frank Bennett wrote:You cannot directly process the XML-based data from a Java application. First you need to read the data and extract the data that is relevant to what you want and then populate one or more Java data objects with this data. Once this data is in object form, you can then do whatever you want with it. There are many, many different way to get the data from XML-based format to object-oriented format and then to relational table format.


Hi Frank,

Thanks for the insights.

It's mainly the translation from XML to the object form what I'm wondering about. As the data in the XML message isn't typed and the XML message itself has zero or more repetitions, I'm wondering about the best way to do so. Sure, splitting up the XML into some objects would a good way to start.

Suppose I were to do so, could you give me any advice on how to do this? As I'm a newbie I'm more concerned about learning and understanding the process than I'm concerned about maximum performance (and the like).

Thanks again!
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Sure, splitting up the XML into some objects would a good way to start.


This is basically the only way to start if you are processing XML-based data with an object-oriented program.

For starters you should attempt to create an object-oriented data model which represents the data that you want to process. Take a look at your XML file and try to design an object model for it focusing on modelling the data only. Don't think about behaviour, just data and a model for the data.




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle this kind of XML