有大虾也能给我一份吗?[email protected]

解决方案 »

  1.   

    /**
       * 这个方法使用XMLOutputter将JDom对象输出到文件
       * @param myDocument 将要输出的JDom对象
       * @param filePath 将要输出到的磁盘路径
       * @param encoding 编码方式
       */
      public static void OutputToFile(Document myDocument, String filePath,
                                      String encoding) {
        //setup this like outputDocument
        try {
          XMLOutputter outputter = new XMLOutputter("", true, encoding);
    //这里可以设置换行和空格,具体可以查看javadoc。      //output to a file
          FileWriter writer = new FileWriter(filePath);
          outputter.output(myDocument, writer);
          writer.close();
        }
        catch (java.io.IOException e) {
          e.printStackTrace();
        }
      }
      

  2.   

    不解。我现在要实现用jsp从数据库取数据,同时用xml表现,像csdn那样,如何做啊?
      

  3.   

    “用xml表现”需要用xsl或css来格式化
      

  4.   

    编号: 57 发送者 tzjfoo 发送时间 2003-11-12 9:56:27 删除  回复  
    内容 http://expert.csdn.net/Expert/topic/2450/2450357.xml?temp=.4288446谢谢你的回复^_^//这里可以设置换行和空格,具体可以查看javadoc。
    但是我还是不知道具体该怎么写, 你能告诉我吗? 谢谢!! 写了个例子演示一下:1.  XMLOutputter outputter = new XMLOutputter("", true, "GB2312");输出结果如下:<root>
    <sub1>subtext1</sub1>
    <sub2>subtext2</sub2>
    </root>2.XMLOutputter outputter = new XMLOutputter("  ", true, "GB2312");
    <root>
      <sub1>subtext1</sub1>
      <sub2>subtext2</sub2>
    </root>3.XMLOutputter outputter = new XMLOutputter("  ", false, "GB2312");<root><sub1>subtext1</sub1><sub2>subtext2</sub2></root>
    下面是jdom的api帮助,看看就明白了:Constructor Detail XMLOutputter public XMLOutputter()This will create an XMLOutputter with no additional whitespace (indent or newlines) added; the whitespace from the element text content is fully preserved.XMLOutputter public XMLOutputter(java.lang.String&nbsp;indent)This will create an XMLOutputter with the given indent added but no new lines added; all whitespace from the element text content is included as well.Parameters:indent - the indent string, usually some number of spacesXMLOutputter public XMLOutputter(java.lang.String&nbsp;indent,
                        boolean&nbsp;newlines)This will create an XMLOutputter with the given indent that prints newlines only if newlines is true; all whitespace from the element text content is included as well.Parameters:indent - the indent String, usually some number of spacesnewlines - true indicates new lines should be printed, else new lines are ignored (compacted).XMLOutputter public XMLOutputter(java.lang.String&nbsp;indent,
                        boolean&nbsp;newlines,
                        java.lang.String&nbsp;encoding)This will create an XMLOutputter with the given indent and new lines printing only if newlines is true, and encoding format encoding.Parameters:indent - the indent String, usually some number of spacesnewlines - true indicates new lines should be printed, else new lines are ignored (compacted).encoding - set encoding format. Use XML-style names like "UTF-8" or "ISO-8859-1" or "US-ASCII"
      

  5.   

    谢谢你 wellsoon(wellsoon)
    但是我还是有个问题,因为我做的补写xml文件
    用你给我的方法,
    <root>
      <sub1>subtext1</sub1>
      <sub2>subtext2</sub2>
    </root>
    补写了3,4的话会形成
    <root>  <sub1>subtext1</sub1>  <sub2>subtext2</sub2></root>
    <root>
      <sub3>subtext3</sub3>
      <sub4>subtext4</sub4>
    </root>
    再写一次又会多一行空行(我要写n多次,可能无限长),我需要解决多余的空行,帮帮我!谢谢!!
      

  6.   


    这个是jdom自身的问题,我也遇到过,目前没有比较好的办法。我现在是把换行设置为false,在需要换行的最终输出(也就是说输出之后不再更改)的时候,我再把换行设置为true。多余的空行并不会影响数据的读写。我在定义好元素之后,就是用写xsl进行处理了,所以是否空行太多对我影响不大。你试试其它办法吧。
      

  7.   

    谢谢wellsoon(wellsoon),揭帖!!