Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java-XML app re-design 1

Status
Not open for further replies.

varocho

Programmer
Dec 4, 2000
238
US
I have a servlet that instantiates another class that calls six stored procedures and the data returned from each stored procedure is used to create a different section of an XML file. The class uses the JDOM API to create the file. Then the XML file is validated against an XSD file, and if there are errors, then the 'invalid' records are removed from the appropriate sections. Because of this step, records - in XML format - are stored in HashMap objects, with 1 HashMap per section. So when errors occur, records are removed from the HashMaps and a new, final XML file is created. However, since the heap size on our production Weblogic Server has been reduced from 128MB to 32MB, my code now throws an OutOfMemory exception.

One solution might be to change the stored procedures so only valid records are returned, but if the XSD file changes, then the stored procedures will have to be changed as well. (Right now, I use a couple of utility classes I created that use the 'SAXParser' class and a 'DefaultHandler' subclass to find and save validation error messages.)

Another possible solution I've been considering was to not use the HashMaps at all, just create the original file and if there are validation errors, then use regular expressions (somehow) to update the XML in the file by removing the invalid records.

Thoughts, anyone?
 
How do you know which records are invalid? Since you do know can’t you just remove them from the DOM tree? That would obviate the HashMap wouldn’t it?

-pete
I just can't seem to get back my IntelliSense
 
Pete, thanks for responding. Removing invalid records is somewhat tricky, because removing a record from section 1 requires removing associated records in sections 2, 3, 4 and maybe 5 and updating a count record in section 6. Also the 'removeChildren' method of the JDOM 'Element' class isn't exactly what I'm looking for. That method seems to be require a tag name, but I don't want to remove all of the records in a specific section, rather a specific record in a specific section. I need a method that can remove a record from 'Section1' with a specific 'InternalID' value. So if I have N 'Section1' records:

<Section1>
...
</Section1>
<Section1>
...
</Section1>
...
<Section1>
<InternalID>5</InternalID>
</Section1>
...
<Section1>
...
</Section1>

Ideally I'd like to be able to remove the 'Section1' record with 'InternalID' value of 5 with 1 method call. I don't think that's possible with the JDOM API.
 
I don't know about JDOM but with standard DOM removeChild takes the specific Node object to be removed. The Node can be obtained using an XPath query.

Don't know if that helps

-pete
I just can't seem to get back my IntelliSense
 
Hello, varocho & palbano.

Try to use Xerces instead of JDOM. Xerces is better than JDOM, so maybe it helps.

Regards, and good luck!

Polu.
 
Yeah, that's one of the standard DOM parsers that i was referring to.

-pete
I just can't seem to get back my IntelliSense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top