Results 1 to 5 of 5
- 05-29-2012, 08:48 PM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
How do I skeletonize XML using the DOM object?
I have thousands of variations of the ubber-simplified XML listed below which I must "Skeletonize" and create an output version of the new transformed xml. (Spaces replaced with dots to maintain indentation for readability)
I need to remove some of the elements, blank out others, and blank out some attributes, to create the resulting skeleton XML which still has the <stateCounty> element and all it's children, deleted the <buildInfo> element and children, and removed the values from the attributes and element data in <userInfo>'s children as shown below.Java Code:</sampleDoc> <stateCounty> <state abbreviation="CA" fips="06"> <name>California</name> </state> <county code="RV" fips="065"> <name>Riverside</name> </county> </stateCounty> <buildInfo> <date>20120529</date> <time>11.08.00</time> </buildInfo> <userInfo> <userId> <id securityLevel="23">12345678</id> <name>Fred Flintstone</name> </userId> </userInfo> </sampleDoc>
I am traditionally a mainframe programmer and am fairly new to Java. I have been searching for information on how to use the DOM object, but don't understand how to determine the difference between the /sampleDoc/stateCounty/state/name and /sampleDoc/userInfo/userId/name elements? They both seem to have the same element name "name".Java Code:</sampleDoc> <stateCounty> <state abbreviation="CA" fips="06"> <name>California</name> </state> <county code="RV" fips="065"> <name>Riverside</name> </county> </stateCounty> <userInfo> <userId> <id securityLevel=""></id> <name></name> </userId> </userInfo> </sampleDoc>
If anyone can provide any insight on how to process this tree, your assistance would be greatly appreciated.
Mitch HarperLast edited by Fubarable; 05-31-2012 at 10:45 PM. Reason: code tags added
- 05-30-2012, 09:46 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: How do I skeletonize XML using the DOM object?
If you have anyone with xslt (ie xml transformation) knowledge then I would simply transform the former into the latter.
It's a pretty simple one (assuming that is the actual data format).
If not, and you need to do this via Java, then you might want to use a SAX parser, which will let you trace down the tree.
Failing that (and since you seem to be looking at DOM) you could use XPath.Please do not ask for code as refusal often offends.
- 05-30-2012, 10:21 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Re: How do I skeletonize XML using the DOM object?
Because I'm a lazy old sod I'd use a SAXParser and use an extension of a DefaultHandler object; that DefaultHandler is used as a callback function when the SAXParser parses the XML text. No fat DOM model is created and you can create your skeleton output while the input is being parsed; all lean and mean ;-)
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-30-2012, 11:36 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: How do I skeletonize XML using the DOM object?
I'd transform it myself.
But then I did shed loads of that a few years back, so it's almost second nature.
The DOM is a problem, especially if the source is big.Please do not ask for code as refusal often offends.
- 05-31-2012, 08:57 PM #5
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Any chance of getting original type of object from Map<String, Object>?
By Tim99 in forum New To JavaReplies: 1Last Post: 01-09-2012, 04:46 PM -
Insert class file as object in a table & read the object from the blob.
By facemeguru in forum New To JavaReplies: 1Last Post: 02-02-2011, 06:11 PM -
Create object of unknown class, based on existing object
By Zack in forum New To JavaReplies: 2Last Post: 06-22-2010, 04:29 AM -
[Paremeters] in a method(Object expA, Object expB){}
By Unsub in forum New To JavaReplies: 2Last Post: 01-29-2010, 02:01 AM -
how to pass an arraylist from an object back to the parent object that it was created
By george_a in forum New To JavaReplies: 1Last Post: 03-04-2009, 06:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks