again with xml

again with xml

View Answers

September 10, 2008 at 11:25 AM

hello

Antony

Read this page and related link.

http://www.informit.com/library/content.aspx?b=STY_XML_21days&seqNum=207

Thanks
Rajanikant

September 10, 2008 at 4:58 PM

Hi


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

public class ElementNode {
static public void main(String[] arg) {
try{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a XML file name: ");
String xmlFile = buff.readLine();
File file = new File(xmlFile);
System.out.print("Enter an element which have to delete: ");
String remElement = buff.readLine();
if (file.exists()){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer tFormer = tFactory.newTransformer();
Element element = (Element)doc.getElementsByTagName(remElement).item(0);
// Remove the node
element.getParentNode().removeChild(element);
// Normalize the DOM tree to combine all adjacent nodes
doc.normalize();
Source source = new DOMSource(doc);
Result dest = new StreamResult(System.out);
tFormer.transform(source, dest);
System.out.println();
}
else{
System.out.println("File not found!");
}
}
catch (Exception e){
System.err.println(e);
System.exit(0);
}
}
}

---------------------------------------------

getElementsByTagName(): This getElementsByTagName() method returns a NodeList of all descendant Elements with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree.

getChildNodes(): This is a method. This getChildNodes() method returns a NodeList that contains all children of this node.

getParentNode(): The parent of this node. All nodes, except Attr, Document, DocumentFragment, Entity, and Notation may have a parent.

nextSibling(): The node immediately following this node. If there is no such node, this returns null.

------------------------------------

Visit for more information.

http://www.roseindia.net/xml/dom/DOMCloneElements.shtml


Thanks & Regards

Amardeep









Related Tutorials/Questions & Answers:
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.../xml/dom/DOMCloneElements.shtml Thanks & Regards Amardeep
There and Back Again
There and Back Again       The weblog of Joshua Eichorn, AJAX, PHP and Open Source Read full DescriptionADS_TO_REPLACE_1
Advertisements
ModuleNotFoundError: No module named 'again'
ModuleNotFoundError: No module named 'again'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'again' How to remove the ModuleNotFoundError: No module named 'again'
ModuleNotFoundError: No module named 'again'
ModuleNotFoundError: No module named 'again'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'again' How to remove the ModuleNotFoundError: No module named 'again'
again java - Java Beginners
again java  i will ask iam using servlets ,in one program my requirement is if there is a image(if u like) in anywhere and we browse that image and it is store in u r account like orkut. my doubt is if the image is stored
again java - Java Beginners
again java  Hi, i will ask iam using servlets ,in one program my requirement is if there is a image(if u like) in anywhere and we browse that image and it is store in u r account like orkut. my doubt is if the image
java again - Date Calendar
java again  I can't combine your source code yesterday, can you help me again. My problem is how we get result jtextfield2 from if jtexfield1 we enter(jTextfield keypressed) then the result out to jTextfield2, This my jFrame
ModuleNotFoundError: No module named 'lambada-again'
ModuleNotFoundError: No module named 'lambada-again'  Hi, My... 'lambada-again' How to remove the ModuleNotFoundError: No module named 'lambada-again' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lambada-again'
ModuleNotFoundError: No module named 'lambada-again'  Hi, My... 'lambada-again' How to remove the ModuleNotFoundError: No module named 'lambada-again' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'nested_again'
ModuleNotFoundError: No module named 'nested_again'  Hi, My Python... 'nested_again' How to remove the ModuleNotFoundError: No module named 'nested_again' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'showit-again'
ModuleNotFoundError: No module named 'showit-again'  Hi, My Python... 'showit-again' How to remove the ModuleNotFoundError: No module named 'showit-again' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'testpay-again'
ModuleNotFoundError: No module named 'testpay-again'  Hi, My... 'testpay-again' How to remove the ModuleNotFoundError: No module named 'testpay-again' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lambada-again'
ModuleNotFoundError: No module named 'lambada-again'  Hi, My... 'lambada-again' How to remove the ModuleNotFoundError: No module named 'lambada-again' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'n-again'
ModuleNotFoundError: No module named 'n-again'  Hi, My Python...-again' How to remove the ModuleNotFoundError: No module named 'n-again... to install padas library. You can install n-again python with following command
ModuleNotFoundError: No module named 'testpay-again'
ModuleNotFoundError: No module named 'testpay-again'  Hi, My... 'testpay-again' How to remove the ModuleNotFoundError: No module named 'testpay-again' error? Thanks   Hi, In your python
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  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  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
matching database again - Java Beginners
matching database again  Dear experts, So happy I get through this ask a question page again. Thank God. I want to say "A BIG THANK YOU" for helping me about the matching codes. It is working now after fine tuning
XML
XML  Hi...... Please tel me about that Aren't XML, SGML, and HTML all the same thing?ADS_TO_REPLACE_1 Thanks
Read data again - Java Beginners
Read data again  sir, i still hav a problem,first your code will be change like this : in netbeans out message error 5. Can you help me again. My database like my question before.Can you fix and find the problem in my code
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
Read data again - Java Beginners
Read data again  Hey, i want to ask again about how to read data from txt, My DB: kd_div varchar(15), nm_div varchar(30), dep varchar(25), jab varchar(35), cab varchar(15), ket varchar(30) My data in txt file is://i
Hi..Again Doubt .. - Java Beginners
Hi..Again Doubt ..  Thank u for ur Very Good Response...Really great.. i have completed that.. If i click the RadioButton,,ActionListenr should get call. It should add to the MS Acess table..Plz check this out.... hope u ill
doesnt run again - Java Beginners
the soltion   Hi I am sending u again the code, this code run in my
Hi .Again me.. - Java Beginners
Hi .Again me..  Hi Friend...... can u pls send me some code on JPanel.. JPanel shoul have 1pic 1RadioButton .. Like a Voter List... REsponse me..  Hi friend, import java.io.*; import java.awt.
ModuleNotFoundError: No module named 'make-figures-great-again'
ModuleNotFoundError: No module named 'make-figures-great-again'  Hi...: No module named 'make-figures-great-again' How to remove the ModuleNotFoundError: No module named 'make-figures-great-again' error? Thanks  
ModuleNotFoundError: No module named 'testing-python-again'
ModuleNotFoundError: No module named 'testing-python-again'  Hi...: No module named 'testing-python-again' How to remove the ModuleNotFoundError: No module named 'testing-python-again' error? Thanks   Hi
ModuleNotFoundError: No module named 'testing-python-again'
ModuleNotFoundError: No module named 'testing-python-again'  Hi...: No module named 'testing-python-again' How to remove the ModuleNotFoundError: No module named 'testing-python-again' error? Thanks   Hi
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 - 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
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. It is a language for selecting nodes from an XML document. It is used
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
Drop Down Reloads again in IE..How to prevent this?
Drop Down Reloads again in IE..How to prevent this?  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down
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
help again plz sorry - Java Beginners
help again plz sorry  Thanks for giving me thread code but i have a question this code is comletelly right and i want to make it runs much faster for that i made 5 threads but 2 things i dont understand 1- with one
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
Java XStream
; XStream is a simple library used to serialize the objects to XML and back again.... It provides clean and consistent XML. With XStream it requires no modifications to objects. XStream allows to integrate with other XML APIs very easily

Ads