Home Answers Viewqa Java-Beginners Java-Change Xml values

 
 


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

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 Pages:
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
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  if we are giving negitive values in load-on-startup> tag wt is result Blockquote
how to read values from java in xml?
how to read values from java in xml?  how to read values from java in 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
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
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
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
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
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
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
XML in database - XML
XML in database  Hi Deepak, i m again facing problem with single element multiple tag in xml. i m trying to read the tag values into my... this xml into my db(which is in mysql) i write the following code. import
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
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
java - XML
java  How to read the values of XMLStreamConstants.CDATA in simple java
XML Validation
nested XML attribute values must always be quoted  ... XML Validation       XML with correct syntax is Well Formed XML. XML validated against a DTD
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 to display initial and renewal rate. Like if he enter all the attribute values starting
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
DOM - XML
DOM  Hello.... I'm creating an xml file from java using DOM... from the database values... and saving it in a file But the created xml file..."),rs.getString("email")); } System.out.println("Xml File Created
HTML - XML
change the remaining combobox.while i select the second combobox then automatically change the remaing two.. when i select first combobox then automatically all the following comboboxes will be change depending on the first
retrieve multiple attribute values
XML retrieve multiple attribute values  Hello All Am a beginner. Would like some help with this. The following is part of my XML file: <...; What I would like is to retrieve both the attribute values of process
retrieve multiple attribute values
like some help with this. The following is part of my XML file: <process... like is to retrieve both the attribute values of process:Output during execution time, store them so that it can be retrieved for later use using Java. Thanks
retrieve multiple attribute values
like some help with this. The following is part of my XML file: <process... like is to retrieve both the attribute values of process:Output during execution time, store them so that it can be retrieved for later use using Java. Thanks
XML Schema
. Default and fixed values for elements and attributes Power of XML Schema XML...: #FFFFFF; } XML Schema An XML Schema defines how to structure an XML document and it can be used in place of DTD. XML Schema is based on XML. XML Schema
how to seach a keyword in a xml file - XML
how to seach a keyword in a xml file  i have a xml file. i wanted to read and store all the tag values. i have a html form in which when i enter some keyword say "a" then it has to display the tag values starting with a letter
accessing xml using java
-text-values-from-a-nodel.shtml http://www.roseindia.net/xml/dom/GetData.shtml...accessing xml using java  I need to retrieve some elements in xml file using java   Hi Friend, Please visit the following links: http
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>
parsing xml using sax
parsing xml using sax  how to get values if the root elements are same and their attributes are different
create a xml from sql server 2005 - XML
create a xml from sql server 2005  hello Dear, i want to know how we create a xml file which retrieve data from Sql server 2005 using java. i... with the name as 'student' i want to create a xml file from the table values which
Comparing XML with HTML
than storing data. It also eliminates the need to change in html when xml... are not. Attribute values must always be quoted in xml while its not the case...Comparing XML with HTML XML and HTML are both designed for different purposes
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
Parsing XML using Document Builder factory - XML
Parsing XML using Document Builder factory  Hi , I am new to XML . I am trying to parse a XML file while is : For this i am using Document... 144.35.3.90 144.35.3.91 I want to read all the tag values . I am able to do so
retrieve in xml file in struts2
retrieve in xml file in struts2  i am using struts2 and trying... properties file using ajax. i now put the values from properties file to map... can i get back the value from the xml file in the ajax function and print
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
Read XML using Java
xml and compare values with DB2 database and generate a report. So First of all i need to read xml using java . i did good research in google and came to know...://www.roseindia.net/xml/sax/EmployeeDetails.shtml http://www.roseindia.net/java/example/java
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
XML
XML  How i remove a tag from xml and update it in my xml
XML in JAVA - Java Beginners
XML in JAVA  hi.. i have an XML file .. and i have parsed... in another file to get all the elements in the documents.. but my java SDK(i.e Eclipse) gives Java Null Pointer exception... can anyone tell me what could be wrong
Introduction to XML
Introduction to XML An xml file consists of various elements. This section presents you a brief introduction to key terminologies used in relation to xml. Here is a sample xml code: .style1 { background-color: #BFDFFF
XML, XML Tutorial, XML Tutorial Online, XML Examples, XML Tutorial Example
with Java Processing XML with Java DOM JDOM...XML XML Tutorials and examples In this section we will learn XML with the help of tutorials and example code. If you are a beginner in XML then learn
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.