java and xml problem. plz see this 1 first

java and xml problem. plz see this 1 first

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>xxx</Username>
<Password>xxx</Password>
</AuthHeader>
</soapenv:Header>
<soapenv:Body>
<ocs:doService>
<ocs:in0>
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>

<zsmart>

<Data>
<header>
<ACTION_ID>ModDefLang</ACTION_ID>
<REQUEST_ID>002009031100001</REQUEST_ID>
</header>

<body>
<MSISDN>22508591226</MSISDN>
<UserPwd></UserPwd>
<DefLang>1</DefLang>
</body>
</Data>

</zsmart>


]]>

</ocs:in0>
</ocs:doService>
</soapenv:Body>
</soapenv:Envelope>s

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 Tutorials/Questions & Answers:
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... in your XML file: "); //String str = bf.readLine(); int no = Integer.parseInt("1
problem 1 - Java Beginners
problem 1   Hi, please help me!!!! How can i code in java using Two-dimensional Arrays? This question is related to the one i posted before. this is my input data file: 88 90 94 102 111 122 134 75 77 80 86 94 103 113 80
Advertisements
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... XML file: "); //String str = bf.readLine(); int no = Integer.parseInt("1
XML load problem - XML
, Plz give full details with source code to solve the problem and visit to : http://www.roseindia.net/xml/dom/ Thanks    New Document...XML load problem  I have load the xml document in javascript.getting
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example
sir plz do respond to my problem immediately - Java Beginners
sir plz do respond to my problem immediately  Hello sir, Iam very happy that you have responded to my problem.The code u sent... code(sent by you).plz inject that code into my browser code so that it can show
problem 1 = C#
Relational operators   help this problem plsss
really need help on how to write this program plz some 1 help out. - Java Beginners
really need help on how to write this program plz some 1 help out.  i am confused here on what to write can some 1 help out here i dont quite understand how to code it so can some 1 help out. Part II Write, compile and execute
xml problem - XML
xml problem  URGENT>>>>> how to retrieve data from hash tables without a JDBC connection?????? Thanks & Regards SAIBHARGAV146
What to See in Jaipur in 1 Day?
We are discussing about the important places that visitors must see in one day trip to Jaipur. A planned trip is something that one does not always get, but that does not imply that unprepared trips are pathetic experiences unless you
SEE with Java
SEE with Java       Position Vacant: SEE with Java Job Description  Java...: SEE with Java
facing problem plz help me out - Framework
Facing problem plz help me out  hi i am new to servlet i deployed... the web.xml file too parallel to the classes folder now i am facing this problem.plz tell me what to do... error:The requested resource (Servlet servlet
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... FileOutputStream(lsPath+"\\Test.xml"); // XERCES 1 or 2 additionnal
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
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
Problem in running first hibernate program.... - Hibernate
Problem in running first hibernate program....  Hi...I am using..., It seems that your class has not been found.There may be problem in your...;xerces-2.6.2.jar ->xml-apis.jar ->JRE system libraries[JRE1.6.0_01
plz help me today plz plz - Java Interview Questions
plz help me today plz plz  2.) Suppose list is an array of six elements of type int. What is stored in list after the following java code executes... int[5]; alpha[0] = 5; for (count = 1; count < 5 * count ++) { alpha[count
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
Plz send - Java Beginners
Plz send  Hi, please send whole code i understood ur sending... be a troublesome...then again wat r ur needs.... so plz...provide a deatiled structure of ur problem.... thanks and reg/ prashu.. [email protected]
population problem plz help me befor 16 March 2011 !!
population problem plz help me befor 16 March 2011 !!  the Q is : How... (String [] args ) { int countYear = 1; int popu = 0... countYear = 1; int popu = 0; System.out.println("pleas enter population
plz help me out with this problem...please write the program for me.thanxxxxx
plz help me out with this problem...please write the program for me.thanxxxxx  Write a program that will print out a hydro bill. The bill will be formatted as the example on the next page. The following information
plz help me out with this problem...please write the program for me.thanxxxxx
plz help me out with this problem...please write the program for me.thanxxxxx  Write a program that will print out a hydro bill. The bill will be formatted as the example on the next page. The following information
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 application PLZ ?
Java application PLZ ?  Write an application that demonstrates each of the following methods, based on the statement String dedicate = ?Dedicated to making your event a most memorable one:; indexOf(?D?) charAt(15) endsWith(one
having problem with menu ans sub menu items css ...plz help!!
having problem with menu ans sub menu items css ...plz help!!  PLZ help ...this is my html menu > <div id="content"> <div > class="navigation" id="nav"> > <div class="item user"> >
Plz give java coding for this
Plz give java coding for this  ... iMin = 1, iMax = 8, iMid; // give max. value in even no. int jMin = 1, jMax...;& j < jMid) || (i == iMax - 1 && j > jMid
java coding help plz ?
java coding help plz ?  Given two integers N and M (N ââ?°Â¤ M), output all the prime numbers between N and M inclusive, one per line. N and M... (i > 1) { if ((number != i) && (number % i
plz help - Java Beginners
Thread in java : First Code : import java.io.PrintWriter; import...plz help  i have to programs and it takes too long to run them so i..... but i dont know how to aplly that on my 2 programs: the first code
Plz answer - Java Beginners
Plz answer  Create a Java Bean Class â?? Customer according to the below given class diagram. Customer... ------------------------------------------------- plz doreply me....thankz alot  
java tree expressions - XML
java tree expressions  hi all, i have a problem in tree expressions. see there is a document tree like a parent document has no. of child... code to solve the problem and visit to : http://www.roseindia.net/java
plz answer - Java Beginners
plz answer   Write a Binary Search program that searches an array... the following series of numbers and run the search on it: 1, 2, 3, 5, 8, 13, 21, 34, 55..., f2 = 0, f3 = 1; for (int i = 0; i < intArray.length; i++) { f1 = f2; f2
Still have the same problem--First Example of Struts2 - Struts
Still have the same problem--First Example of Struts2  Hi I tried the example in the link. But still I am getting the same problem like as I...; Hi friend, Please give details about the problem in details
plz send immediately - Java Beginners
plz send immediately  Hi Deepak, How are you, Deepak I face some problem in my project,plz help me My Questin is user input... should be updated. plz write a code and immediate response its very urgent plz
plz - Java Interview Questions
is between 1 and 6 (inclusive). design and implement a class , called die , to represent a die .the default constructer should initialize a die to the number 1 .your class must contain the method rollDie that returns a number between 1
plz help me - Java Beginners
plz help me  Thanks deepak continue response..i face some problem i hv a these file index.jsp,sessionvalid.jsp, both r store in project folder... is true...but i very confuse that how it is not displayed admin page plz any one
plz help me - Java Interview Questions
plz help me  1)Rewrite the method in exercise 10 such that it use...; if they are not equal , the problem is reduced to searching half of the array . if the search value is smaller than the middle array element, the first half
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-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
plz help me - Java Beginners
plz help me  Deepak I can write a sessioon code plz help me admin_home.jsp page is display but data is not disply plz help me what is wrong
plz help me - Java Beginners
plz help me  Hi, I want to search all field from database using name, and display in text box, then data is update and delete. i want to search name using alphabets a-z, plz reply fast. plz help me this is very urgent
plz help - Java Interview Questions
plz help  1)write a java program that prompts the user to input a decimal number and print the number rounded to the nearest integer? 2)write... don't use "for"  Hi Friend, Try the following code 1) import
help plz - Java Interview Questions
help plz  1 )write a program that does the following : a. prompts... , if the input string is abcd, the output is : edcba plz plz plz plz plz help me   Hi Friend, Try the following: 1) import java.util.
plz Help me - Java Beginners
plz Help me  Hi, I want learn struts,I dont have any idea about this plz help how can i make a framework.If u have any information then plz send my personal id plz tell me that whose software installed.and give me brief
java code7 of 1
java code7 of 1  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g Ã?· t in t time units
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
task 1 - Java Beginners
task 1  Please write a Java client that send a small letters string to a Java server which convert it to uppercase letters and send it back to the client. Please submit both the client and server programs  Hi Friend
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
EXCEPTIONS-----1 - Java Interview Questions
EXCEPTIONS-----1  How To Handle The Exceptions With Out Using Try,Catch And Throws?I Want Region Plz Post Answer
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Try

Ads