Click to See Complete Forum and Search --> : read in an xml file and then create java objects


Rashar
01-18-2005, 06:02 PM
Problem Description:
The goal is to read in an xml file that describes a component sequence and create java objects from the elements.
The XML file describes a sequence of responsibilities related to component and some of these sequences have parallel branches off or merge. The following is an attempted mockup of the image the xml file represents:
- the numbers are the scenario objects and the (---) represents the flow of events in the sequence.

1---------2-------3-----(merges to 8)
4------5------ (merges to 8) ---8-----9-------10----------11
6----------7-------(merges to 8) (from 10)-----12----13

Explanation:
-the sequences that begin at 1,4,6 happen in parallel then merge to one object (8) which continues the sequence to 9 and so on. At then there is a branching off that goes on to both 11 and 12 at the same time (happening in parallel).

The sample XML file that represents this is as follows (excuse the formatting):
<seq>
<par>
<seq>
<par>
<seq>
<do name="1" />
<do name="2" />
<do name="3" />
</seq>
<seq>
<do name="4" />
<do name="5" />
</seq>
<seq> <do name="6" />
<do name="7" />
</seq>
</par>
<do name="8" />
<do name="9" />
<do name="10" />
</seq>
<seq>
<do name="11" />
</seq>
<seq>
<do name="12" />
<do name="13" />
</seq>
</par>
</seq>

The problem:
The end goal is to be able to know which objects related to another by going through the scenario data structure. So what I am attempting to doing is reading these <do> elements and creating a java object for each. As well as creating a scenario object that represents the entire flow of events - the sequence (<seq>)(each scenario will contain the scenario objects - stored in a data structure such as a list or vector). The problem is maintaining the scenario sequence information when there are nested parallel (<par>) with sequence (<seq>) elements.
I need to know the sequence so somehow I need to relate these do object in the scenario data structure instead of just storing everying on one continuous sequence since this will inaccurately represent which objects are related to another object when I go back and search for related objects. I am getting lost in the amount of flags to use (if any), how to store the previous ID within the current object when I enter a nested parallel sequence ( for example, the previous nodes for 8 are 3, 5, and 7. And the previous for 11 is 10 and the previous for 12 is also 10).

Khalid Ali
01-18-2005, 06:28 PM
if I understood you correctly, then you can use DOM(if this is a huge file like tens of megs then DOM will be slower) methods,
What you will need to do is read the xml file and create a Document object then you can et all of the elements with the name do e.g
document.getElementsByTagName("do");
this will return a NodeList object with all of the elements that has name do and from that point on you can loop thru the nodelist and do whatever to each item

Rashar
01-18-2005, 08:03 PM
Hey, thanks Khalid Ali for your reply.

I'll give that a try...

Regards,

Rashar