Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Change the Content of Node by Locating it

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-12-2009
Member
 
Join Date: Nov 2009
Posts: 582
Change the Content of Node by Locating it

Hi, I want the program which will help to locate the node and then to change the content of the node. If anyone have it, please give it to me.
Reply With Quote
  #2  
Old 07-12-2009
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
Re: Change the Content of Node by Locating it

Hi, I think the code given below will help you to get Change the content of node by locating it. Make use of it to get what you want.

Code:
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

public class ContentChange
 {

    public static void main(String[] args) throws Exception
 {
        boolean validating = false;
        DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
        dbfactory.setValidating(validating);

        Document dcmt = dbfactory.newDocumentBuilder().parse(new File("2.xml"));
        new Changecontent().ContentChange(dcmt, "Rohan Gaikwad", "@Techarena.in");
}
    public void ContentChange(Document dcmt, String newname, String newemail)
 {
        Element elmnt = dcmt.getDocumentElement();
        NodeList childnodelist = elmnt.getChildNodes();
        for (int j = 0; j < childnodelist.getLength(); j++)
 {
            
            Node childnode = childnodelist.item(j);
            Node subchildname = childnode.getFirstChild();
            Text text = (Text) subchildname.getFirstChild();
            String oldname = text.getData();
            if (oldname.equals(newname))
 {
                subchildname=subchildname.getNextSibling();
                System.out.println(subchildname.getNodeName());
                text =(Text)subchildname.getFirstChild();
                System.out.println("Old e-mail id: "+text.getData());
                text.setData(newemail);
                System.out.println("New e-mail id: "+text.getData());
            }

        }

    }
}
Reply With Quote
  #3  
Old 07-12-2009
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: Change the Content of Node by Locating it

Hi, I don't have much knowledge about it, But from the internet I have got the code which will help to change the content of node by locating it. Just look at it, if it is helpful to you or not.
Code:
public void changeContent(Document doc,String newname,String newemail) 
{
    Element elroot = doc.getDocumentElement();
    NodeList rootlist = elroot.getChildNodes();
    for(int j=0; j<rootlist.getLength(); j++) 
{
        Element person = (Element)rootlist.item(j);
        NodeList personlist = person.getChildNodes();
        Element elname = (Element)personlist.item(0);
        NodeList namelist = elname.getChildNodes();
        Text nametext = (Text)namelist.item(0);
        String oldname = nametext.getData();
        if(oldname.equals(newname)) 
{
            Element email = (Element)personlist.item(1);
            NodeList emaillist = email.getChildNodes();
            Text emailtext = (Text)emaillist.item(0);
            emailtext.setData(newemail);
        }
    }
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 07-12-2009
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
Re: Change the Content of Node by Locating it

Hi, I am also searching for the same code which will help me to change the content of Node by Locating it. If you are able to get it then please give it to me also. I have searched on internet but didn't got much useful information about it. If you able to get methods which can be useful to you in this case, then you can give me that also, I can check whether it will helpful to me or not. If I am able to get information about this, then I will provide you that.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Change the Content of Node by Locating it"
Thread Thread Starter Forum Replies Last Post
How to change color of selected node in JTree? Juaquine Software Development 5 1 Week Ago 09:02 PM
Locating MAC Address On iPhone GurpreetC Networking & Security 6 20-05-2010 02:37 AM
Converting CDATA Node into Text Node Jagdish Gada Software Development 3 07-12-2009 09:54 AM
How to change Full Post Content to an Excerpt on WordPress Blog Homepage AdityaR Software Development 3 28-09-2009 03:54 PM
How to fix error locating \3\lxcrtime.dll BYRNE Networking & Security 3 26-05-2009 11:03 AM


All times are GMT +5.5. The time now is 04:19 AM.