on 02-20-2008 8:42 AM
Hi,
I am doing hands on using Java Dom.
I have to pick up the xml file from source directory (local pc )and convert into target xml file and store in local pc using java dom
(not using in XI)
In NWDS, I picked up the file and parsed properly finally built the target DOm(domTarget)
Finally i need to transform it and put into folder as xml file.
I ended up as follows, then really dont know what to do.
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
Source req_Input = new DOMSource(docTarget);
Result req_Output = new StreamResult();
transformer.transform(req_Input,req_Output);
can any one provide the few lines of final code
thanks in advance
Hi Neha
For this you have to use file input/output stream for this
the snippet of the code is given below. This might help you.
TransformerFactory transformerfactory =
TransformerFactory.newInstance();
Transformer transformer = transformerfactory.newTransformer
(new StreamSource(new File
(application.getRealPath("/") + "ch09_02.xsl")));
transformer.transform(new StreamSource(new File(application.getRealPath
("/") + "ch09_01.xml")),
new StreamResult(new File(application.getRealPath("/") +
"result.html")));
}
catch(Exception e) {}
FileReader filereader = new FileReader(application.getRealPath("/") +
"result.html");
BufferedReader bufferedreader = new BufferedReader(filereader);
String textString;
while((textString = bufferedreader.readLine()) != null) {
}
filereader.close();
}
Thanks
Abhishek Mahajan
*Please reward points in case helpful*
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Neeha,
prob try with this,
File fout = new File("target.xml");
StreamResult ss = new StreamResult(fout);
Source source = new DOMSource(docTarget);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.transform(source,ss);
FileReader filereader = new FileReader(fout);
BufferedReader bufferedreader = new BufferedReader(filereader);
String textString;
while((textString = bufferedreader.readLine()) != null)
{}
filereader.close();
Hope fully u should see the target doc.
Regards
chandra.dasari@yash.com
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.