|
| |||||||||
| Tags: content, java, locate, node, program |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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. |
|
#2
| ||||
| ||||
| 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());
}
}
}
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#3
| ||||
| ||||
| 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 |
|
#4
| ||||
| ||||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |