Reg:parsing design

Hi i've have alredy posted this under java/xml but no reponse ..not sure if i can post here .. and i need help with the design not code

want to know the right approach for the design .

This is wat my input xml going to be

<xpTransactions>

<transList>

<xpTrans name="ADD_AG">

<childTrans>ADD_ED</childTrans>

<childTrans>ADD_CD</childTrans>

</xpTrans>

<xpTrans name="ADD_ED">

< actionIntf>add_r</actionIntf>

<actionIntf>add_ml</actionIntf>

<actionIntf>sub_mlk</actionIntf>

</xpTrans>

<xpTrans name="ADD_CD">

<actionIntf>add_rkm</actionIntf>

<actionIntf>sub_mlcd</actionIntf>

<actionIntf>sub_mlki</actionIntf>

</xpTrans>

</transList>

</xpTransactions >

input to the java program will be xpTrans name so for eg when the input is ADD_AG i need to check whether it has any child and if it is then nee dto get all the elements underneath it ..so in this case we have two chilsd elements so the output should be

ADD_AG

ADD_ED

add_r

add_ml

sub_mlk

Add_CD

add_rkm

sub_mlcd

sub_mlki

when the input string is goin to be ADD_ED ( this does not have any child so )the output is just need to take all its child only

ADD_ED

add_r

add_ml

sub_mlk

Is it possible to produce a tree structure with above xml ?

if yes then use Jdom and create a tree structure and then store each node and its contents in alist ...is this approach corerct .

or shld i use other parseer and instead of producing tree structure jus store it in array or linked list and then manupalate it .what is the right approach to take ..thanks for the help

[1981 byte] By [siv_gaa] at [2007-10-3 9:28:10]
# 1
hi is there a way i can do this ..any suggesiton will be o fgretahelp
siv_gaa at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 2

Is the format up to you? If it is, why not set it up like this?

<xpTransactions>

<transList>

<xpTrans name="ADD_AG">

<xpTrans name="ADD_ED">

< actionIntf>add_r</actionIntf>

<actionIntf>add_ml</actionIntf>

<actionIntf>sub_mlk</actionIntf>

</xpTrans>

<xpTrans name="ADD_CD">

<actionIntf>add_rkm</actionIntf>

<actionIntf>sub_mlcd</actionIntf>

<actionIntf>sub_mlki</actionIntf>

</xpTrans>

</xpTrans>

</transList>

</xpTransactions >

kindofbluea at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 3
You shouldn't write your own parser.If you want to manipulate the parse tree, then use DOM (as opposed to SAX).
paulcwa at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 4

no i cant change the xml format that isthe problem.

but i think creating a tree structure with this xml will be difficult . so i am thinking of using sax parser to parse the xml for particular xptrans name store it in hash map or linked list then check if it has children then read the xml again and get all the childrens ..only problem is i will be doing multiple reading of XML ..if xml file is huge then this will be a problem performance wise ..is there any other approach i can take ?Thanks for all the help

sivgaa at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 5

You can do it only reading the xml once. Don't try to build the tree structure yet while you're reading it, just store the names of the children in a list under each xpTrans, and put the xpTrans in hash map. Then it'd be trivial to go back through and find the actual children for their names (or you could just use it as is). Know what I mean?

kindofbluea at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 6
oh ok got it thanks for the help ...one last thing you said not to build tree structure you mean use SAX jus to parse and store it in data structure and not DOM .. right ?thanks for the help
sivgaa at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 7
xstream?
mchan0a at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 8

> you said not to build tree structure you mean use SAX

> jus to parse and store it in data structure and not

> DOM .. right ?

Yeah, I was addressing: "so i am thinking of using sax parser to parse the xml for particular xptrans name store it in hash map or linked list then check if it has children then read the xml again and get all the childrens ..only problem is i will be doing multiple reading of XML"

kindofbluea at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...
# 9

OK, now why do you not want to use DOM, when it seems to be exactly what you need?

If for some reason you absolutely don't want to use DOM and prefer to reinvent the wheel -- then for God's sake at least use some stacks and create a real tree structure linking the objects to each other; don't use a HashMap to store the nodes, which would just make things more complicated.

paulcwa at 2007-7-15 4:42:32 > top of Java-index,Java Essentials,New To Java...