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



Home Answers Viewqa Java-Beginners Java-Change Xml values

Have Programming Question? Ask it here!
 
 
 


prasanna.b93
Java-Change Xml values
2 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners



Advertisement
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? 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
XML
XML  How i remove a tag from xml and update it in my xml
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  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  Hi...... Please tel me about that Aren't XML, SGML, and HTML all the same thing? Thanks
XML
XML  please tell me how i remove one tag out of all similar type of tags in xml
xml
xml  how can i remove white space and next line when i copy stream to xml file
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  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  if we are giving negitive values in load-on-startup> tag wt is result Blockquote
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
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
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 - 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
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 - 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 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
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
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
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
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
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
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
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
xml code - XML
xml code  I Read xml is used to store and transfer data can you explain it with sample code
xml certification dumps - XML
xml certification dumps  hi need information. xml certification purpose dumps
Create XML - XML
Create XML   Hi, Can you please provide java code,that will create xxx.XML file where all the attributes and values of those attributes is predefined from java file? Thanks in advance Sumanta  Hi friend
duplicate values
duplicate values  My database having cursor that has duplicate values.i want to remove duplicate values through java application
 

 

 

DMCA.com