java and xml problem. plz see this 1 first

Ads

 
 

Share on Google+Share on Google+

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









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
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 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
SEE with Java
SEE with Java       Position Vacant: SEE with Java Job Description  Java...: SEE with Java
problem 1 = C#
Relational operators   help this problem plsss
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
xml problem - XML
xml problem  URGENT>>>>> how to retrieve data from hash tables without a JDBC connection?????? Thanks & Regards SAIBHARGAV146
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
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
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
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 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.. [email protected]
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
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
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
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
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
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 developed shows only first record ie. only Tom Cruise. please give me
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
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 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 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 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
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
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

Ads

 
Advertisement null

Ads