以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  我测试网上给的JDOM例子出现的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=19097)


--  作者:yuyeahcool
--  发布时间:6/1/2005 1:04:00 PM

--  我测试网上给的JDOM例子出现的问题
这个例子可哪都是,我把在www.jdom.org上的jdom-1.0下载下来了,把build下的jdom.jar放到了JDK的lib下了,而且把jdom-1.0的lib里的.jar都放到了JDK的lib下了,把这些.jar的路径都加到了环境变量classpath下了,但运行E:\ceshi>javac testJDOM.java (testJDOM.java文件放到了E:\ceshi文件夹下了)出现问题,说倒数第二句
XMLOutputter xmlout = new XMLOutputter (indent,newLines,"gb2312"); 里的new是connt resolve symbol,不知道怎么回事,请大家指点,万分感谢!!!!!!

×××还有,请问大家,JDOM的问题我去哪个论坛问问题比较好,麻烦大家了,我是新手,不好意思:)×××××

程序如下:
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"));
XMLOutputter xmlout = new XMLOutputter (indent,newLines,"gb2312");
xmlout.output(doc, new FileOutputStream("exampleB.xml"));
}
};


--  作者:binaryluo
--  发布时间:6/1/2005 7:41:00 PM

--  
XMLOutputter xmlout = new XMLOutputter (indent,newLines,"gb2312");
XMLOutputter里有三个构造函数,分别是:
      XMLOutputter()
      XMLOutputter(Format format)
      XMLOutputter(XMLOutputter that)
你用的这个构造函数不存在,所以不能识别这个标识。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
39.063ms