Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa XML java and xml problem. plz see this 1 first
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


priya
java and xml problem. plz see this 1 first
0 Answer(s)      4 years and 9 months 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>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...

Advertisement
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
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
SEE with Java
SEE with Java       Position Vacant: SEE with Java Job Description  Java...: SEE with Java
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
problem 1 = C#
Relational operators   help this problem plsss
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
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
xml problem - XML
xml problem  URGENT>>>>> how to retrieve data from hash tables without a JDBC connection?????? Thanks & Regards SAIBHARGAV146
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 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
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
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
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
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.. prashobvee@gmail.com
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
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
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
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
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 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
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
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... with a series of words? The first word is ?A? The second word is ?sentence? There are nine words in total Java has a standard to index elements starting
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
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
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... with a series of words? The first word is ?A? The second word is ?sentence? There are nine words in total Java has a standard to index elements starting
que 1 - Java Beginners
que 1  WAP to enter a sentence & count the no. of times a particular word occurs in it.Display the frequency of the searched word. eg- input:the quick brown fox jumps over the lazy dog. word to be searched:the output
array 1 - Java Beginners
array 1  WAP to input values in 2 arrays and merge them to array M.  Hi Friend, Try the following code: import java.util.*; class MergeArray{ public static int[] merge(int [] ... arr) { int arrSize = 0
 

 

 

DMCA.com