Home Answers Viewqa XML java and xml problem

 
 


priya
java and xml problem
0 Answer(s)      3 years and a month ago
Posted in : XML

hi, i need to write a java program that generates an xml file as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ocs="http://ocs.ztesoft.com">
<soapenv:Header>
<AuthHeader xmlns="http://ZTE.com/webservices/">
<Username>aaa</Username>
<Password>vvv</Password>
</AuthHeader>
</soapenv:Header>
<soapenv:Body>
<ocs:doService>
<ocs:in0>
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>

---------

i have witten a program in java, but im not getting the same format as it is here. this is what i have written

import java.io.*;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

import org.w3c.dom.*;

public class CreatXMLFile {
public static void main(String[] args) throws Exception {
//BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//System.out.print("Enter number to add elements in your XML file: ");
//String str = bf.readLine();
int no = Integer.parseInt("1");
//System.out.print("Enter root: ");
//String root = bf.readLine();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement("zsmart");
document.appendChild(rootElement);
Element child = document.createElement("Data");
rootElement.appendChild(child);
Element child1 = document.createElement("Header");
rootElement.appendChild(child1);
Element child2 = document.createElement("ACTION_ID");
child.appendChild(child2);
Text text = document.createTextNode("ModDefLang");
child2.appendChild(text);
//Comment comment = document.createComment("Employee in roseindia");
//child.appendChild(comment);

Element element = document.createElement("REQUEST_ID");
child.appendChild(element);

Text text1 = document.createTextNode("002009031100001");
element.appendChild(text1);

/* Element chilE = document.createElement("Id");
chilE.setAttribute("name", "Vineet");
rootElement.appendChild(chilE);


Text text12 = document.createTextNode("status");
chilE.appendChild(text12);*/

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();

transformer.setOutputProperty(OutputKeys.INDENT, "yes");

// create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(document);
transformer.transform(source, result);
String xmlString = sw.toString();

File file = new File("c:/newxml.xml");
BufferedWriter bw = new BufferedWriter
(new OutputStreamWriter(new FileOutputStream(file)));
bw.write(xmlString);
bw.flush();
bw.close();
}


}

---------
the output i am getting is as follows.

<?xml version="1.0" encoding="UTF-8"?>
<zsmart>
<Data>
<ACTION_ID>ModDefLang</ACTION_ID>
<REQUEST_ID>002009031100001</REQUEST_ID>
</Data>
<Header/>
</zsmart>

can you plz help...
View Answers









Related Pages:
java and xml problem - XML
java and xml problem  hi, i need to write a java program that generates an xml file as follows: aaa vvv --------- i have witten a program in java, but im
Problem with external DTD - XML
Problem with external DTD  Hi, This class generate an XML file.But while I am running that generated xml file its giving error as can not locate... classes. OutputFormat of = new OutputFormat("XML","ISO-8859-1",true); of.setIndent
xml - XML
xml  hi convert xml file to xml string in java ,after getting the xml string result and how to load xml string result? this my problem pls help..."); FileOutputStream output = new FileOutputStream("new.xml"); ReadXML xml = new
Java-XML-DOM - XML
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work.... If there is someone out there that knows java very well, this wouldn't be a problem for him
java and xml - XML
java and xml   test_final_1 2009-025T13:23:45 B2B I... this problem...  Hi Friend, Please visit the following link: http://www.roseindia.net/xml/dom/DOMValidateDTD.shtml Thanks
java and xml problem. plz see this 1 first - XML
java and xml problem. plz see this 1 first  hi, i need to write a java program that generates an xml file as follows: xxx... ]]> s i have witten a program in java
XML load problem - XML
XML load problem  I have load the xml document in javascript.getting..., Plz give full details with source code to solve the problem and visit to : http://www.roseindia.net/xml/dom/ Thanks    New Document
xml problem - XML
xml problem  URGENT>>>>> how to retrieve data from hash tables without a JDBC connection?????? Thanks & Regards SAIBHARGAV146
Read XML in java - XML
Read XML in java  Hi Deepak, I want to read a xml file which have... nikumbh i tried to solve the problem but failed.the program which i hav... a solution.my java code is given below. import java.io.File; import
java with xml
java with xml  hi i have a problem. // this sample code is reading xml file in java DefaultHandler handler = new DefaultHandler... example i copmpare qName with NAME. NAME is xml element. but my problem is when
XML parsing using Java - XML
XML parsing using Java  I'm trying to parse a big XML file in JAVA..." in element "MIRate"(THE XML code is below).once he enters coverage rate I need..." RenewalRate1="0.03100". I'm facing problem switching between tables. Like
Xml append node problem
Xml append node problem   print("code sample");Question: I create a XML which looks like this: <cwMin>31</cwMin> The code used in generating this XML is : XMLOutputFactory xof
java tree expressions - XML
java tree expressions  hi all, i have a problem in tree expressions... code to solve the problem and visit to : http://www.roseindia.net/java... documents. the problem is whenever i click on + sign it means it will have surely have
jasper problem - XML
jasper problem  URGENT PROBLEM!!!!!!!!!!!!! how can we use a hash table in jasper reports to generate reports without using database connection directly but access data from the hash table what we needed for creation
xml
xml  how to creatte html file and validate using java and finally i need get web.xml file
how to update xml from java - XML
friend, To solve your problem, please visit to: http://www.roseindia.net/xml...how to update xml from java  hi, Im new to xml parsing and dont know much about. I need to modify the attribute val of a tag in a complex xml file
XML - XML
XML XSD validation in java  Can anyone help in writing validation for XML XSD in Java
problem
problem  Hi, what is java key words   Hi Friend, Java Keywords are the reserved words that are used by the java compiler for specific... information, visit the following link: Java Keywords Thanks
problem
problem  hi'sir mai niit student hu.mujhe java ka program samaj me nhi aata mai kya karu and mai kaise study karu please help me.   Learn Java from the given link: Java Tutorials
parsing XML file to get java object - XML
parsing XML file to get java object  Hello, I'm facing a problem in parsing XML file to get the java object. I've tried to retrieve data from XML file using SAX parser. my XML file structure is the following
problem in database
problem in database   thanks for web site. I want change this code...="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C...; //web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID
xml - XML
xml  how to match to xml file?can you give example with java code
create a xml from sql server 2005 - XML
create a xml from sql server 2005  hello Dear, i want to know how we create a xml file which retrieve data from Sql server 2005 using java. i am briefing my problem as follows. let i have a table in sql server 2005
how to convert text file to xml file in java. - XML
how to convert text file to xml file in java.  Hi all, I m having some problem. Problem is I want to convert a text file which is having the no of record(i.e no of different line of information)to a xml file through java
Problem facing in SAX Parsing - XML
Problem facing in SAX Parsing  I have facing the issue in SAX Parsing like i have got the xml and the xml structure is like below... can find the above xml there is no CountryCode in the second record and 4th
Problem facing in SAX Parsing - XML
Problem facing in SAX Parsing  I have facing the issue in SAX Parsing like i have got the xml and the xml structure is like below... 0668420957700159USD you can find the above xml
java and xml - XML
java and xml  Hi Deepak, I want learn xml and java(applications). Which editor is best usefull(trial--version) in my applications...; Hi friend, http://www.roseindia.net/xml/dom/ Thanks
data retrivel code - XML
database into an XML file using java.  Hi Shruti, Please visit the following link given for solving your problem. http://www.roseindia.net/servlets/login-Xml-servlet.shtml I hope this will help you a lot. Thanks
Java + XML - XML
Java + XML  1) I have some XML files, read one xml... java...the attribute value..not sure now how to read the xml file passing..." pointing to a hello xml file ..read that file and get the value of the parent
servlet program problem - Java Beginners
servlet program problem   i used ur servlet example prg with xml file of helloworld program and i run dat program in tomcat, it shows only... file to run it  Hi Friend, Please clarify your problem. Thanks
XML in java - XML
XML in java  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them...://www.roseindia.net/xml/sax/SAXElementCount.shtml Hope that it will be helpful
XML with JAVA - XML
document and the processing in JAVA program . Find the time for each XML element...XML with JAVA  Hi.. This is Priya here. Thanks for responding me. I have a query. "Write program in java to evaluate the time to access
Writing xml file - Java Beginners
Writing xml file  Thank you for the quick response The values which...;Hi friend, Code to solve the problem : import java.io.*; import java.sql.... XmlServlet().createXmlTree(doc); System.out.println("Xml File Created
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
downloading created xml file - Java Beginners
downloading created xml file  Hi... I've an application where i need to create an xml file and when a button is clicked it has to prompt me for saving the xml file so i created xml file successfully and whats the problem
java - XML
java  How can write data into XML file using DOM parser? How can convert HTWL file to XML file
Java code to parse xml - Java Beginners
Java code to parse xml   TL1 10.50.26.98... ........... ........... ........... .......... ..... ....... ....... ....... the problem... xml . after fetching the values i have to use them in the same order i mean like
java - XML
This is my XML file then how can read this XML file Using DOM & SAX parsers in java? How can write the same data into XML file using DOM parser? Could you
java - XML
java  How to prepare an xml document by reading data from a table in the database . (the database access logic is written inside the servlet
java - XML
you get the data3. And in the servlet class you can use the DOM api to create xml... it to the xml treedoc.appendChild(root);For more information please visit http://www.roseindia.net/xml/dom/createdomchildelement.shtmlThanks
java program for writing xml file - Java Beginners
java program for writing xml file  Good morning i want to write values from my database(one table)into one xml file. Like i have 3 coloumns in my... xml file and storet that in particlar location. Please help me out Thanks
xml or database - XML
the problem : "parsingxml.jsp" Parsing of xml using JDOM...xml or database  If I implement some web applications, which is a better way to retrieve and parse xml file directly using DOM or storing those xml
xml developing - XML
xml developing  I want to develop XML document with following DTD file with XML format. I have also XSL file as a externatl file to represent my xml in browser. my problem is i want to create AUTO unique ID & checksum for each
xml developing - XML
xml developing  I want to develop XML document with following DTD file with XML format. I have also XSL file as a externatl file to represent my xml in browser. my problem is i want to create AUTO unique ID & checksum for each
Java-Change Xml values - Java Beginners
Java-Change Xml values   test_final_1 2009-025T13:23:45 B2B I have the following xml.. I want to change the values of , and .. Can... one could give me the code for the problem by using NodeList.... import
java - XML
java  how can i validate my xml file using java code plz send me de... kumar  Hi friend, Step to validate a xml file against a DTD (Document Type Definition) using the DOM APIs. Here is the xml file "User.xml
XML and java
XML and java  Hi I have xml data in XMLStreamreader object how to retrive tha data and write into a file using java Your help will be much appreciated Thanks   Hi Friend, Try the following code: import java.io.
how to write in xml? - XML
how to write in xml?  can anybody give the code how to write in xml...;Hi friend, Code to help in solving the problem : import java.io.*; import...(new InputStreamReader(System.in)); System.out.print("Enter XML file name
java - XML
in the XML document while i am parsing the file using SAX event based parser.... provide the way in java.  Hi Friend, Try the following code: import... parser = parserFact.newSAXParser(); System.out.println("XML Data

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.