import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.crimson.tree.*;
import java.io.*;public class a
{
public static void main(String args[])
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("Books.xml");
NodeList nl =doc.getElementsByTagName("Information");
Element node=(Element) nl.item(0);
node.getElementsByTagName("Topic").item(0).getFirstChild().setNodeValue("aaa");
node.getElementsByTagName("Content").item(0).getFirstChild().setNodeValue("bbb");
node.getElementsByTagName("Date").item(0).getFirstChild().setNodeValue("ccc");
node.getElementsByTagName("Source").item(0).getFirstChild().setNodeValue("ddd");
((XmlDocument)doc).write(new FileWriter("Books.xml"));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
import org.w3c.dom.*;
import org.apache.crimson.tree.*;
import java.io.*;public class a
{
public static void main(String args[])
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("Books.xml");
NodeList nl =doc.getElementsByTagName("Information");
Element node=(Element) nl.item(0);
node.getElementsByTagName("Topic").item(0).getFirstChild().setNodeValue("aaa");
node.getElementsByTagName("Content").item(0).getFirstChild().setNodeValue("bbb");
node.getElementsByTagName("Date").item(0).getFirstChild().setNodeValue("ccc");
node.getElementsByTagName("Source").item(0).getFirstChild().setNodeValue("ddd");
((XmlDocument)doc).write(new FileWriter("Books.xml"));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货