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

 
 


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









Related Pages:
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
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
Logging Tutorial - Part 1
Logging Tutorial - Part 1 2000-12-14 The Java Specialists' Newsletter [Issue 003] - Logging part 1 Author: Dr. Heinz M. Kabutz If you are reading... (System.out.println springs to mind). In that case you are back to the first problem of too
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
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
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
SEE with Java
SEE with Java       Position Vacant: SEE with Java Job Description  Java...: SEE with Java
unable to see the output of applet. - Applet
://www.roseindia.net/java/example/java/applet/FirstApplet.html but the problem...unable to see the output of applet.  Sir, I was going through the following tutorial http://www.roseindia.net/java/example/java/applet
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 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
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 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
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
Java programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program..., the largest and the average value for a set of integer marks. The program will first.../java/example/java/swing/ Thanks
spring first example - Spring
spring first example  I am trying my first example of spring from the link http://www.maestric.com/doc/java/spring/setup But I am not getting... Software Foundation\Tomcat 5.5\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C
plz help me!!!!!!!! - JSP-Servlet
html file,.java file and xml file.. under which directory or folder i`ve to save these files.. and also during compilation of java file,class file is created.but...plz help me!!!!!!!!  i`ve set the environment varaibles for tomcat
java - XML
java  how can i validate my xml file using java code plz send me de code iam in urgent requirement help me plz thanks and regards vijay kumar  Hi friend, Step to validate a xml file against a DTD (Document
java problem - Java Beginners
of choices to the user with the following choices: 1 See available rooms...java problem  Room.java This file defines a class of Room objects... in the Room object remains in the range 1..4 inclusive. · A writer method
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
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
Plz give the answers - Java Interview Questions
Plz give the answers  1.Computing cos(x) using the cosine series...), is the number itself. Write a JAVA program to find all perfect numbers between 2 and 10000. Example: 28 is a perfect number( 1 + 2 + 4 + 7 + 14 = 28) 3.Given
Hint: Java session problem - WebSevices
Hint: Java session problem  Hai, My problem is : In a jsp form i have... and again if i open a second case form w/o closing the first opened case form, i can see the first case fields & its values on the secong case form
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
plz. answer my ques - Java Beginners
"); } } }   1) first create "retry.jsp" page (this displays...plz. answer my ques  I want to ask a prog. prob which would create... servlet is given as below: 1. Validation.java import java.io.*; import
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 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
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 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
JDOM example in java, How to read a xml file in java.
JDOM example in java, How to read a xml file in java. In this tutorial, we will see how to  read a xml file in java. Code. Student.xml...;   <info id="1"  >     
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
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
Processing XML with Java
; } Processing XML with Java XML is cross-platform software, hardware... Html and XML were developed for different purposes. 1. Html is a widely used... and not the replacement. Sample XML document Below is sample xml file. You can see how
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
read xml
read xml   hi all, i want to ask about how to read an xml in java ME.. here is the xml file <data> <value> <struct>... of the first value node after the data node, i just can get only 1 struct but not 2, how
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
My first Java Program
My first Java Program  I have been caught with a practical exam to do the following: Write a program that takes input from a user through... You may not "cut off" any words in the middle I can be able to code step 1
XML - XML
of occurrences of each element type in an XML document and display them. The document file to be processed should be identified by the first command-line argument. ...)); System.out.print("Enter XML file name:"); String xmlFile = bf.readLine
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
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 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 1 = C#
Relational operators   help this problem plsss
String Exercises 1 - Answers
Java: String Exercises 1 - Answers Answers to the String Exercises 1. 3 -- s refers to exactly the same string as a. ERROR -- t is a local variable, and it must be assigned a value first. "1abc" -- + means concatenation
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
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 solve my query?
plz solve my query?  how to remove all the options from select control in html using java script?   JavaScript remove all items <...) { var i; for(i=selectbox.options.length-1;i>=0;i--) { selectbox.remove(i
contructors 1&test
contructors 1&test   how do i Create a class named Box that includes... the 'XXX' with the value of length using the Java keyword this in your code. â??h The constructor that takes two arguments should assign the first value to length
bliffoscope data analsys problem
bliffoscope data analsys problem  Bliffoscope Data Analysis Problem It's April 1, 2143. Your job is to save the world. Well, a little world... problem you have is detecting the Rejectos spaceships and slime torpedos, because
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