This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I need a urgent help on XML topics, I have written a Java code which can take a XML file, and parse it, and read the value from the XML, upto this working fine,
Now, after collecting the values, I want to take one more XML file, In this what ever the value I have take from the previous one, I have to replace with the New XML file, here i don't know how to do it.
For this I am using the SAX parse to take the values, but I don't know how to write a XML file, with the new value,
Thankyou for you kind attention, :roll: Prasanna :roll:
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35250
7
posted
0
Most of the XML tree APIs can generate files: DOM, JDOM, dom4j, XOM. The last time I generated actual XML files I used XOM (tutorial), but any of these will do.
If you need to do a lot of XML processing in Java, it will pay off to become familiar with JAXP, which is the standard API for dealing with XML in Java. Some links about it can be found in the XML FAQ.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
1
posted
0
For this I am using the SAX parse to take the values, but I don't know how to write a XML file, with the new value,
There is nothing magical about an XML document, it is just text that follows certain formatting rules. In your class that gets the SAX "events" just write the (possibly modified) content corresponding to each event to an output file. No need to make things any more complicated than that. Bill
I think I replied to a question similar to this one some time ago. I generally suggest XSLT over a SAX based filter because it's better suited for the job of transforming XML. Also the XSLT approachs scales upward better when you consider how ugly the SAX logic would grow over time with changing requirements. On another note, you could use a SAX filter to solve the problem rather elegantly. I have to run now, I'm outta time but it's something you might want to read up on.
Holla at me...<br /><a href="http://codeforfun.wordpress.com" target="_blank" rel="nofollow">http://codeforfun.wordpress.com</a>
Clifton Craig
Ranch Hand
Joined: May 26, 2006
Posts: 103
posted
0
You want to extend the org.xml.sax.helpers.XMLFilterImpl class. You would override the startElement() method and put logic there to check for certain elements or call super.startElement() for all others. When your specific elements are encountered you can call super.startElement() and pass the name of the element you want to change to or whatever. Just drop you extended XMLFilterImpl into a SAX transform and off you go.
prasanna kanth
Greenhorn
Joined: May 14, 2006
Posts: 28
posted
0
Hi,
Thanx for ur valuable advice, the problem is solved...
I have take the xml values form SAX and put it in the Hashtable, and through DOM I parsed the new XML file, and changed the values where i required....