以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Java/Eclipse 』  (http://bbs.xml.org.cn/list.asp?boardid=41)
----  JDOM操作XML的问题,请帮忙看看  (http://bbs.xml.org.cn/dispbbs.asp?boardid=41&rootid=&id=9653)


--  作者:yu145
--  发布时间:8/31/2004 5:25:00 PM

--  JDOM操作XML的问题,请帮忙看看
我下的样本代码,运行就出问题,我改来改去还是这个问题,我实在没办法了,大家走过路过帮忙看看,给点建议帮帮咱菜菜。。。(N个菜)鸟

问题如下:(我觉得是属性的问题。。(废话)):
F:\tomcat\jakarta\webapps\jdomExamples\Article.java:71: cannot resolve symbol
symbol  : method addAttribute  (org.jdom.Attribute)
location: class org.jdom.Element
        carElement.addAttribute(new Attribute("vin", "123fhg5869705iop90"));
                  ^
F:\tomcat\jakarta\webapps\jdomExamples\Article.java:100: cannot resolve symbol
symbol  : method addAttribute  (java.lang.String,java.lang.String)
location: class org.jdom.Element
        license.addAttribute("state", "CA");
               ^
Note: F:\tomcat\jakarta\webapps\jdomExamples\Article.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
2 errors

出问题的代码是:
    public static Document createDocument() {
        // Create the root element
        Element carElement = new Element("car");
        //create the document
        Document myDocument = new Document(carElement);
        //add an attribute to the root element

        carElement.addAttribute(new Attribute("vin", "123fhg5869705iop90"));

        //add a comment
        carElement.addContent(new Comment("Description of a car"));

        //add some child elements
        /*
         * Note that this is the first approach to adding an element and
         * textual content.  The second approach is commented out.
         */
        Element make = new Element("make");
        make.addContent("Toyota");
        carElement.addContent(make);
        //carElement.addContent(new Element("make").addContent("Toyota"));

        //add some more elements
        Element model = new Element("model");
        model.addContent("Celica");
        carElement.addContent(model);
        //carElement.addContent(new Element("model").addContent("Celica"));
        Element year = new Element("year");
        year.addContent("1997");
        carElement.addContent(year);
       // carElement.addContent(new Element("year").addContent("1997"));
        Element color = new Element("color");
        color.addContent("green");
        carElement.addContent(color);
        //carElement.addContent(new Element("color").addContent("green"));
        Element license = new Element("license");
        license.addAttribute("state", "CA");
        license.addContent("1ABC234");
        carElement.addContent(license);
        //carElement.addContent(new Element("license").addContent("1ABC234").addAttribute("state", "CA"));
        return myDocument;
    }


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
8,750.000ms