This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Dear All: Consider this scenario. Have got a xml file. whose data have been loaded to bunch of tables (not the entire xml has been loaded but only 25% of it, rest are intact in xml file). Have updated the tables...changed some data. Now that xml file and db data has gone out of synch, would like to generate a new xml file putting together data from the original xml file as well as modified data from db.... Am finding it difficult how do I parse one xml and write another xml file maintaining the same structure. Can anyone pls help?
Could you describe the structure of your XML file and the changes that you need to be able to merge into it? Also, is this XML file small, big, huge, what? It's probably easiest to read the XML into a Java object model, read the database changes into a similar object model, and then Just Write The Logic for merging the two.
The xml file's structure is very deep and the attribute values will be changing in the data base, which we need to capture. For example, consider this piece from the xml file.... [CODE] <UML:Class name="Person" xmi.id="EAID_620A1B15" visibility="public" namespace="EAPK_E977D80E" isRoot="false" isLeaf="false" isAbstract="false" isActive="false"> <UML:ModelElement.stereotype> <UML:Stereotype name="eai.person"/> </UML:ModelElement.stereotype> <UML:ModelElement.taggedValue> <UML:TaggedValue tag="isSpecification" value="false"/> <UML:TaggedValue tag="ea_stype" value="Class"/> <UML:TaggedValue tag="ea_ntype" value="0"/> <UML:TaggedValue tag="version" value="1.0"/> <UML:TaggedValue tag="package" value="EAPK_E977D80E"/> <UML:TaggedValue tag="date_created" value="2003-05-07 14:54:28"/> <UML:TaggedValue tag="date_modified" value="2003-10-29 12:46:47"/> <UML:TaggedValue tag="gentype" value="Java"/> <UML:TaggedValue tag="tagged" value="1"/> <UML:TaggedValue tag="package_name" value="Meta Model"/> <UML:TaggedValue tag="phase" value="1.0"/> <UML:TaggedValue tag="complexity" value="1"/> <UML:TaggedValue tag="status" value="Proposed"/> <UML:TaggedValue tag="stereotype" value="eai.person"/> <UML:TaggedValue tag="style" value="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;"/> </UML:ModelElement.taggedValue> </UML:Class> [CODE] Here the attributes that are captured in the db are: name, xmi.id, visibility, namespace of UML:Class and phase, version, complexity, stereotype of UML:TaggedValue. All other values are not stored in db. These captured values in db are changeable. So, when re-generating the xml from revised data in db, i need to maintain the info in xml which are not initially stored to db, then only xml file would be complete. The xml file is huge its size can be go up to couple of Megs. I would like to know more abt the Java data model.. could u pls give me more info on that? TIA
Joined: Jan 23, 2002
Ok. The XMI looks like simple and small enough for reading into memory in full. Here's how I would do it: 1) Parse the XML file into a org.w3c.dom.Document using DocumentBuilder#parse() 2) Do Document#getElementsByTagName() to get a list of all UML:Class nodes 3) Iterate through each returned Class node 4) Check each attribute's value in the database, calling Element#setAttribute() to replace the old value if the two are out-of-synch 5) Write the Document back to the disk [ February 05, 2004: Message edited by: Lasse Koskela ]
Joined: Jun 17, 2000
Originally posted by Lasse Koskela:
5) Write the Document back to the disk [ February 05, 2004: Message edited by: Lasse Koskela ]
Thanks Lasse. I am able to perform all things above except Step (5). If I write doc.toString(), it writes only
How do I write this into the disk? (I am using FileWriter to write the document into a xml file) TIA
posted October 06, 2004 06:17 AM -------------------------------------------------------------------------------- Hi all
I am developing a messaging application in xml which is extensively used to transfer data between database, middle tier and client tier.
From client side I will get xml string without any table names (its like xml document). I have to extract values w.r.t column namesfrom xml string and insert the values into Oracle database. Can anyone send a snippet of code or links to achieve this functionality, its bit urgent.