新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     >>W3CHINA.ORG讨论区<<     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论DOM, SAX, XPath等。
    [返回] W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWLXML.ORG.CN讨论区 - XML技术『 DOM/SAX/XPath 』 → 我测试网上给的JDOM例子出现的问题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3348 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 我测试网上给的JDOM例子出现的问题 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     yuyeahcool 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:52
      门派:XML.ORG.CN
      注册:2005/6/1

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给yuyeahcool发送一个短消息 把yuyeahcool加入好友 查看yuyeahcool的个人资料 搜索yuyeahcool在『 DOM/SAX/XPath 』的所有贴子 引用回复这个贴子 回复这个贴子 查看yuyeahcool的博客楼主
    发贴心情 我测试网上给的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"));
    }
    };


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/6/1 13:04:00
     
     binaryluo 帅哥哟,离线,有人找我吗?
      
      
      威望:6
      等级:研二(Pi-Calculus看得一头雾水)(版主)
      文章:679
      积分:5543
      门派:IEEE.ORG.CN
      注册:2005/2/19

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给binaryluo发送一个短消息 把binaryluo加入好友 查看binaryluo的个人资料 搜索binaryluo在『 DOM/SAX/XPath 』的所有贴子 引用回复这个贴子 回复这个贴子 查看binaryluo的博客2
    发贴心情 
    XMLOutputter xmlout = new XMLOutputter (indent,newLines,"gb2312");
    XMLOutputter里有三个构造函数,分别是:
          XMLOutputter()
          XMLOutputter(Format format)
          XMLOutputter(XMLOutputter that)
    你用的这个构造函数不存在,所以不能识别这个标识。
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/6/1 19:41:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DOM/SAX/XPath 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/8/1 10:10:54

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    46.875ms