Home Answers Viewqa Java-Beginners XML remove tags

 
 


Varsha Yadav
XML remove tags
1 Answer(s)      2 years ago
Posted in : Java Beginners

how i update a tag from xml file?

View Answers

May 26, 2011 at 5:01 PM


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

public class UpdateXML {
    public static void main(String args[]) {
        try {
            File file = new File("c:/new.xml");
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = factory.newDocumentBuilder();
            Document doc = docBuilder.parse(file);
            Element root = doc.getDocumentElement();
            Element element = (Element) doc.getElementsByTagName("Address").item(0);
            Element childElement = doc.createElement("ContactNo");
            root.replaceChild(childElement, element);
            TransformerFactory transfac = TransformerFactory.newInstance();
            Transformer trans = transfac.newTransformer();

            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(doc);
            trans.transform(source, result);
            String xmlString = sw.toString();
            OutputStream os;
            byte buf[] = xmlString.getBytes();
            os = new FileOutputStream("C:/new.xml");
            for (int i = 0; i < buf.length; i++) {
                os.write(buf[i]);
            }
            os.close();
            buf = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}









Related Pages:
XML remove tags
XML remove tags  how i update a tag from xml file
XML remove tags
XML remove tags  when i remove a tag from xml, it create blank spaces or next line. how i protect it to updae in my xml
Regular Expression for removing XML Tags
Regular Expression for removing XML Tags  Hi, Good Afternoon.I want a Regular expression in java which is removing the XML Tags in the specified... after applying regular expression is only "How are you".Need to remove all XML
XML
XML  please tell me how i remove one tag out of all similar type of tags in xml
Tags in XML - XML
Tags in XML  What are the Tags of XML  In XML there is no predefined tag. Every user can write their own tags at the time of creating it or later. You can define as many tag as you want according to your requirement
tags in xml - XML
tags in xml  Can I use : (colon )in xml tag? For ex. Is this valid?  Hi Friend, You can use colon(:) in XML tag.But is not valid. Thanks
JSTL XML Tags
JSTL XML Tags       PART-4 - JSTL  &  SQL-TAGS   Tutorial Home | Part 1... on JSTL,the author deals with the 'sql' tags in JSTL  and shows how
how to remove tags in HTML without functionalities? - Java Beginners
how to remove tags in HTML without functionalities?  hi to all, I create an application for converting html to ppt in java. And in this i convert the text from html to ppt and i able to remove the HTML tags from .html code
Overview of JSTL Tags
;serializable"     XML Manipulating Tags in JSTL XML stands... on the result of an XPath expression.   The tags in XML flow control... is that the XML flow control tags are applied to the XPath expressions.  The common tags
Use of Core XML tags in JSP
Use of Core XML tags in JSP   ... Tags: Core XML tags provides access to XML data and used to parse these data. There are three tags in this Core XML tag set. 1. <x:out> : This tag
XML
XML  How i remove a tag from xml and update it in my xml
xml
xml  how can i remove white space and next line when i copy stream to xml file
JSTL XML Tags
JSTL XML Tags No one can have any second opinion about the elegance of xml... and such terms, and it may have been none too easy to learn. But the xml tags... to study them. Making our study even easier, many of the xml tags in JSTL
i want to remove specific node in xml file
i want to remove specific node in xml file   <A> <B>hi <C>by <A> <B>hellow <C>how r u ? i want to delet node which is == hellow using java program please help me . tanks in advance
Remove Element from XML Document
Remove Element from XML Document       In this section, you will learn to remove any element from a given  XML document. Whenever you remove the xml element from the xml document
XML - XML
language much like HTML used to describe data. In XML, tags are not predefined. A user defines his own tags and XML document structure like Document Type...XML  What is specific definatio of XML? Tell us about marits
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... tags in separate file. please provide me solution to get values for xml tags
Solution to get vaues for xml tags fform sql database in java
Solution to get vaues for xml tags fform sql database in java  hi I have written a code in java to get these xml tags < company comp:loc=" "/>...(" "). how do i get these values.. already connected database and created xml tags
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
JSP Tags
JSP Tags In this section we will learn about the JSP tags. This section describes you about the various aspects of JSP tags such as what is JSP tag, list of JSP tags, JSP custom tags and many more things. What is JSP Tags ? Tags
JSTL XML Tags
in this tutorial you will learn JSTL XML examples
JSP custom tags
JSP custom tags       JSP custom tags are the user-defined following a special XML syntax to which JavaBean tags (useBean getProperty and setProperty) uses. When Servlet container
JDOM Element Example, How to remove attribute of xml element in java.
JDOM Element Example, How to remove attribute of xml element in java. In this tutorial, we will see how to remove attribute of xml element in java with the help of JDOM library. It is a java tool kit for xml parsing. With the help
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
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... DefaultHandler(){ private Hashtable tags; public void startDocument
JDOM Element Example, How to add and remove child from xml file.
JDOM Element Example, How to add and remove child from xml file. In this tutorial, we will see how to add and remove child node in an xml Document tree. We can add child any where in xml document tree with the help of JDOM API
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
JSTL XML Tags Part 2
In this tutorial you will learn some more example about JSTL XML
xml_append - XML
xml_append  hi i have a xml file im.xml its contents: asaddasahellojim i have to add more tags to .. pls help me to solve this.. ...://www.roseindia.net/xml/ Thanks
Reg XML - XML
. It is a markup language much like HTML used to describe data. In XML, tags are not predefined. A user defines his own tags and XML document structure like...Reg XML  How can I become an XML programmer?What are the channels I
Facelet remove Tag
Facelet remove Tag          This tag is used to remove content within... where jsfc attribute is used and set to the ui:remove is not considered
Design and develop custom tags
Design and develop custom tags...;   Design and develop custom tags Custom... of custom tags that invoke custom actions in a JavaServer Pages (JSP) file
Control Tags-If / Else If / Else
Control Tags-If / Else If / Else       In this section we are going to discuss the various control tags ( The Control Tags...'}"/> Among if, elseif and else tags only one tag evaluates at a time
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
JDOM Element Example, How to remove child of an element from xml file in java.
JDOM Element Example, How to remove child of an element from xml file in java. In this tutorial, we will see how to remove child of an element from xml file... for manipulating, creating and serializing  xml file. With the help of this java
XML Interviews Question page7,xml Interviews Guide,xml Interviews
; and then remove the DocType Declaration so it becomes a well-formed DTDless XML file... XML Interviews Question page7       If XML is just a subset of SGML, can I use XML
again with xml - XML
again with xml  hi all i am a beginner in xml so pls give me...)); System.out.print("Enter a XML file name: "); String xmlFile = buff.readLine...)doc.getElementsByTagName(remElement).item(0); // Remove the node element.getParentNode
Advantages of XML
Advantages of XML   hello, what are the advantage of XML?   Hii, These are the some advantage of xml 1.It is as easy as HTML. 2.XML... application which is capable of processing XML irrespective of the platform
JSTL- xml tag library - XML
JSTL- xml tag library  i was trying to try jstl-xml tags examples.... exception javax.servlet.ServletException: java.io.FileNotFoundException: /jstl_xml/books.xml root cause java.io.FileNotFoundException: /jstl_xml/books.xml note
XML Validation
a closing tag XML tags are case sensitive XML elements must be properly... XML Validation       XML with correct syntax is Well Formed XML. XML validated against a DTD
What is XML?
the data on the web browser. Where as XML just contains the data in proper tags...What is XML? In the first section of XML tutorials we will learn the basics of XML and then write our first xml document. After completing this section
XML Expat Library:
XML Expat Library:       PHP's XML parser is based on Expat. It lets you parse but not validate XML documents means  it does not allow us to find out the XML tags which
Own tag in XML
Own tag in XML  Hi.... Does XML let me make up my own tags? please anyone give the answer Thanks
Remove history
Remove history  how to remove history in struts2 after clicking on logout link
Comparing XML with HTML
and how to use tags and elements in an xml document. XML does not have predefined tags while HTML has. XML lets you invent your own tags while html gives you predefined tags and you have to use them only. XML is extensible
Using JSP in pure XML generating conforming XHTML
; Example program to demonstrate using JSP in pure XML generating conforming XHTML This JSP example describes how JSP tags for XML can be used in XML generation.../TR/xhtml1/DTD/xhtml1-transitional.dtd" &gt; Some of the important tags used
XML Count Elements
XML Count Elements       Here providing you an example that counts the number of tags <Emp_Id> that are used in your XML document using the SAX parser.  Description of program
XML Tutorial
was designed to display data and to focus on how data looks. XML tags... XML Tutorial XML Tutorial: XML stands for EXtensible Markup Language. In our XML tutorial you will learn what XML is and the difference between
html tags
html tags  html tags   Java Struts HTML Tags
XML Parsers
XML Parsers       XML parser is used to read, update, create and manipulate an XML document. Parsing XML Documents To manipulate an XML document, XML parser is needed. The parser

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.