Java中与XML有关的类有哪些? java的那个包好像叫jaxp。个人觉得还是apache的jdom包比较好用。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 xml.apache.orgXerces Java 2 , Xalan Java 2 我已经下载了Xerces Java 2 , Xalan Java 2我想读取xml文件中的信息,请问该如何做?给个例子,谢谢 http://www.jdom.org/前面我记错了,jdom不是apache的项目。 yoken(雨泉) :能给个读取xml文件中的信息的例子吗 import org.jdom.*;import org.jdom.output.*;import org.jdom.input.*;import java.io.*;public class TestJDOM{ public static void main(String args[])throws Exception{ SAXBuilder sb = new SAXBuilder(); //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 Document doc = sb.build(new FileInputStream("exampleA.xml")); //加入一条处理指令 ProcessingInstruction pi = new ProcessingInstruction ("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\""); doc.addContent(pi); Element root = doc.getRootElement(); //得到根元素 java.util.List books = root.getChildren(); //得到根元素所有子元素的集合 Element book = (Element)books.get(0); //得到第一个book元素 //为第一本书添加一条属性 Attribute a = new Attribute("hot","true"); book.setAttribute(a); Element author = book.getChild("author"); //得到指定的字元素 author.setText("王五"); //将作者改为王五 //或 Text t = new Text("王五");book.addContent(t); Element price = book.getChild("price"); //得到指定的字元素 //修改价格,比较郁闷的是我们必须自己转换数据类型,而这正是JAXB的优势 author.setText(Float.toString(50.0f)); String indent = " "; boolean newLines = true; XMLOutputter outp = new XMLOutputter(indent,newLines,"GBK"); outp.output(doc, new FileOutputStream("exampleB.xml")); }}; import org.jdom.*;import org.jdom.output.*;import org.jdom.input.*;import java.io.*;public class TestJDOM{ public static void main(String args[])throws Exception{ SAXBuilder sb = new SAXBuilder(); //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 Document doc = sb.build(new FileInputStream("exampleA.xml")); //加入一条处理指令 ProcessingInstruction pi = new ProcessingInstruction ("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\""); doc.addContent(pi); Element root = doc.getRootElement(); //得到根元素 java.util.List books = root.getChildren(); //得到根元素所有子元素的集合 Element book = (Element)books.get(0); //得到第一个book元素 //为第一本书添加一条属性 Attribute a = new Attribute("hot","true"); book.setAttribute(a); Element author = book.getChild("author"); //得到指定的字元素 author.setText("王五"); //将作者改为王五 //或 Text t = new Text("王五");book.addContent(t); Element price = book.getChild("price"); //得到指定的字元素 //修改价格,比较郁闷的是我们必须自己转换数据类型,而这正是JAXB的优势 author.setText(Float.toString(50.0f)); String indent = " "; boolean newLines = true; XMLOutputter outp = new XMLOutputter(indent,newLines,"GBK"); outp.output(doc, new FileOutputStream("exampleB.xml")); }}; jdom,用过了你就知道好了,很清晰明了,速度也很快 用IBM的dom4j比较好了, 支持XPath不过还没有找到支持xinclude 的 javax.xml.parsersjavax.xml.transformorg.w3c.domorg.xml.sax Java问题 请演示一下从readObject()里面调用defaultReadObject()的例子 定义二叉树,并实现其中序遍历,前序遍历,后序遍历; 对象序列化问题,急在线等,请高求指点 paint问题 [求助]如何让JButton的背景透明? 请教高手帮忙,文本换行与JSP页面换行的转变。解决必给高分!! 一个新建群....504692 java高手进来看看了 在多个页面中调用同一个bean,scope=session 提示java.lang.ClassCastException 连接ms sql数据库的问题,请各位帮忙,就剩90分了,唉。。。。。。 二维数组排序
Xerces Java 2 , Xalan Java 2
我想读取xml文件中的信息,请问该如何做?
给个例子,谢谢
不过还没有找到支持xinclude 的
javax.xml.transform
org.w3c.dom
org.xml.sax