Java-Change Xml values

Java-Change Xml values

View Answers

December 9, 2009 at 5:01 PM

Hi Friend,

Try the following code:

import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.xpath.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class DOMParser {
static String inputFile = "buyer.xml";
static String outputFile = "C:/hello.xml";

public static void main(String[] args) throws Exception {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(inputFile));

new DOMParser().edit(doc);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
}

public void edit(Document doc) {
NodeList list = doc.getElementsByTagName("Order");
Node node1 = list.item(0);
Element element1 = (Element)node1;
NodeList list1 = element1.getElementsByTagName("BuyersID");
for (int idx = 0; idx < list1.getLength(); idx++) {
list1.item(idx).setTextContent("id1");
}

Node node2 = list.item(1);
Element element2 = (Element)node1;
NodeList list2 = element1.getElementsByTagName("utcc:IssueDateTime");
for (int idx = 0; idx < list2.getLength(); idx++) {
list2.item(idx).setTextContent("09-12-2009");
}

Node node3 = list.item(2);
Element element3 = (Element)node1;
NodeList list3 = element1.getElementsByTagName("utcc:KCIType");
for (int idx = 0; idx < list3.getLength(); idx++) {
list3.item(idx).setTextContent("A");
}
}
}

Thanks

December 9, 2009 at 6:21 PM

Thanks a lot for your patient reply.....Its working fine now...









Related Tutorials/Questions & Answers:
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 any one please tel me the code to update the values for the tags metioned above
Atomic values in Xml
Atomic values in Xml  Hi..... please give me the ans How you define atomic values in Xml?ADS_TO_REPLACE_1 Thanks
Advertisements
how to read values from java in xml?
how to read values from java in xml?  how to read values from java in xml
How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example
How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example
dynamically how to change attiribute values in xml
dynamically how to change attiribute values in xml   Hi, I am facing the problem to update the Attribute values in XML file.dynamically how to change attribute values in XML . for example below is my XML structure. text
Need to retain the values on submiting the form - XML
Need to retain the values on submiting the form  I have created the form using XML and XSL, with textbox,checkbox,textarea and two button submit and RESET. how to retain the values in the same page on clicking submit
How to values from xml using java?
How to values from xml using java?  Hi All, I want to read value from following < Line> xml using java.. In < Line>,data is in format of key and value pair.. i want to read only values..could u plz help me
solution to get values for xml namespace tags from sqldatabase in java
solution to get values for xml namespace tags from sqldatabase in java  hi I have written a code in java to get these xml tags < company comp:loc... field(" "). how do i get these values.. already connected database and created xml
Want solution to get values for xml namespace tags from database in java
Want solution to get values for xml namespace tags from database in java  hi I have written a code in java to get these xml tags < company comp... xml tags in separate file. please provide me solution to get values for xml tags
Passing values in ComboBox from XML file
Passing values in ComboBox from XML file In this tutorial we are going to know how we can pass a values in ComboBox by using XML.  This example will examine how to parse and expose XML information using the JAXP with a JSP page
How to parse the attributes values from XML using KXML parser in j2me
How to parse the attributes values from XML using KXML parser in j2me  hai team, i did xml parsing from serverside...i got a resultant value from xml,but here tag value name only came from parsing attribute name cant come
Need solution to get values for XML namespace tags from SQL database in Java
Need solution to get values for XML namespace tags from SQL database in Java  hi I have written a code in java to get these xml tags < company... and created xml tags in separate file. please provide me solution to get values for xml
Can anybody help how to store values to the following xml from .NET application
Can anybody help how to store values to the following xml from .NET application  Can anybody help how to store values to the following xml from .NET application <SQLSchema> <Databases>
xml
xml  what is name space,xml scema give an example for each   XML Namespaces provide a method to avoid element name conflicts.They are used for providing uniquely named elements and attributes in an XML document
Hibernate Named Native SQL in XML Returning Scalar
In this section, you will learn to execute Hibernate named native SQL query written in XML mapping file which return scalar values(raw values
xml - XML
to compute values (strings, numbers, or boolean values) from the content of an XML... friend, XPath : It is a language for finding information in an XML document. It is used to navigate through elements and attributes in an XML document
XML
XML  How i remove a tag from xml and update it in my xml
xml
xml  why the content written in xml is more secure
xml
xml  validate student login using xml for library management system
xml
xml  validate student login using xml for library management system
xml
xml  how can i remove white space and next line when i copy stream to xml file
XML
XML  please tell me how i remove one tag out of all similar type of tags in xml
XML
XML  create flat file with 20 records. Read the records using xml parser and show required details
xml
xml  what is xml   Extensible Markup Language (XML... that is both human-readable and machine-readable. It is defined in the XML 1.0... gratis open standards. The design goals of XML emphasize simplicity, generality
xml
xml  if we are giving negitive values in load-on-startup> tag wt is result Blockquote
XML
XML  Hi...... Please tel me about that Aren't XML, SGML, and HTML all the same thing?ADS_TO_REPLACE_1 Thanks
hibernate.archive.autodetection values
are the hibernate.archive.autodetection values? How to use the hibernate.archive.autodetection in Hibernate project? Thanks   Hi, You can use the class, hbm as values... XML files in your project. Here is example: <property name
XML
XML  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
xml
xml  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
XML - XML
XML  What is specific definatio of XML? Tell us about marits and demarits of XML? use of XML? How we can use of XML?  Hi, XML... language much like HTML used to describe data. In XML, tags are not predefined
XML - XML
XML XSD validation in java  Can anyone help in writing validation for XML XSD in Java
XML - XML
XML  How to run XML program?  Hi Friend, Please visit the following links: http://www.roseindia.net/xml/ http://www.roseindia.net/xml/dom/ Hope that it will be helpful for you. Thanks
XML with JSP - XML
the values in to my jsp from XMl..pls help me in this issue...XML with JSP  Hai all,, I have a doubt..is it possible to submit jsp form data in to xml... i mean after filling the HTML form when i give submit
XML - XML
XML  How to convert database to XML file?   Hi Friend, Do you want to store database data into xml file ? Please clarify this. Thanks
xml - XML
xml  how to match to xml file?can you give example with java code
xml - XML
xml  define parser and xml,in jaxp api how to up load parsers... then the program contains syntax errors. XML is defined as an extensible... information,Examples and Tutorials on Xml visit to : http
xml - XML
xml  hi convert xml document to xml string.i am using below code... = stw.toString(); after i am getting xml string result, like Successxxx profile... Friend, Please visit the following link: http://www.roseindia.net/xml/reading
Convert Text To XML
Convert Text To XML       Here we are discussing the conversion of a text file into xml file by giving an example. This example creates an xml file with its root
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
Convert Object To XML
into xml file as child node values. Convert Object To XMLTo create a xml file pass... Convert Object To XML       Here we are discussing the conversion of an object into xml
duplicate values
duplicate values  My database having cursor that has duplicate values.i want to remove duplicate values through java application
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
xml parsing - XML
xml parsing  Hi i want to parse the xml document which contains US en tages but the values of the tags are in differet language for ex greek...± how can i do this?   Hi friend, Parsing The XML File using DOM
reain values
if it already exits i m using reuest.sendredirect to same jsp but all textbox values are cleard, i want to retain all values in textboxs after request.sendredirect .Please
Consolidated XML to individual XML - XML
Consolidated XML to individual XML  How to separate the consolidated XML file to separate the individual XML names, when a user import the consolidated XML file
Values to listbox
Values to listbox  I have two textboxes by the name street and city.I have an add button and a name listbox. When I enter street and city and press.... Plz help me out with the coding in java script...plz
XML - XML
XML  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them. The document file...)); System.out.print("Enter XML file name:"); String xmlFile = bf.readLine
xml indexing
xml indexing  i need code to give index values to the XML node.The value should be preceded by the parents index value,that is if the parent's index value is 1 then the first child should have value 1.1 and second child should
Retrive Values
Retrive Values  I want to retrive the values between the td by the id using the javascript.So please help me... html form like this <TABLE width="100%" bgColor=""> <TR> <TD ID="td1">Cell 1</TD>

Ads