Results 1 to 6 of 6
- 07-10-2010, 07:05 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
problem wrinting into xml file...
hi pals,
i have a thread which creates nodes for the the document now the problem is tat when i try to supply document object into
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
this does not gives me xml code while the thread is running as i stop the application
i get only the following output.....
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
which i think means that DOMsource could not read document object while the thread is in running state!
can any one help me out to solve this problem??
- 07-10-2010, 08:43 AM #2
Member
- Join Date
- Mar 2010
- Location
- New Delhi,Vadodara
- Posts
- 50
- Rep Power
- 0
First Create file With FileConnection Object
Then call this code.
This is Working for me.
U have to made Some Channges with Ur Requirment. Ok.
public void createXmlTree(Document doc,String userid,String passwd) throws Exception
{
Element root=doc.createElement("user");
doc.appendChild(root);
Element child1=doc.createElement("UserID");
root.appendChild(child1);
Text text=doc.createTextNode(userid);
child1.appendChild(text);
Element ele=doc.createElement("Password");
root.appendChild(ele);
Text text1=doc.createTextNode(passwd);
ele.appendChild(text1);
TransformerFactory tf=TransformerFactory.newInstance();
Transformer trans=tf.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter sw=new StringWriter();
StreamResult result=new StreamResult(sw);
DOMSource dom=new DOMSource(doc);
trans.transform(dom, result);
String xmlString=sw.toString();
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
bw.write(xmlString);
bw.flush();
bw.close();
}
- 07-10-2010, 12:51 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
after foing through google i have found that there are 2 ways to create Document object!!!
first way
DocumentBuilderFactory documentBuilderFactory=DcumentBuilderFactory.newIn stance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
(I have used this method for creating Document object.....)
Second way
Document document = (Document) Class.forName("com.ibm.xml.dom.DocumentImpl").newI nstance();
(And now when i try this one i am returned with the following error[java.lang.ClassNotFoundException: com.ibm.xml.dom.DocumentImpl] which means in the first method "DocumentImpl" is not found and i cannot make out wat is the problem behind it)
document's object is being created within a thread i have tried putting "Synchronized" too still during debugging i dont find y "DocumentImpl" is missing!!!
- 07-10-2010, 01:14 PM #4
Is there a missing jar file that has this class?ClassNotFoundException: com.ibm.xml.dom.DocumentImpl]
- 07-10-2010, 01:37 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
can any thing be done or an any onw tell me where to get this jar file from?
- 07-10-2010, 01:52 PM #6
Member
- Join Date
- Mar 2010
- Location
- New Delhi,Vadodara
- Posts
- 50
- Rep Power
- 0
Similar Threads
-
jar file problem
By abhijit in forum New To JavaReplies: 12Last Post: 02-12-2010, 09:06 AM -
Jar File Problem
By Moncleared in forum New To JavaReplies: 10Last Post: 10-18-2009, 07:43 AM -
jar file problem
By nishant.4545 in forum New To JavaReplies: 1Last Post: 07-03-2009, 08:36 PM -
problem - using a jar file
By jon80 in forum New To JavaReplies: 6Last Post: 07-07-2008, 07:49 AM -
problem with jar file pls help
By jinu5 in forum New To JavaReplies: 0Last Post: 08-15-2007, 10:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks