简介 目录 评价 推荐
  • 程序员慕虎 2019-11-18

    生成子节点和内容并设置换行

    http://img4.mukewang.com/5dd246aa0001bc9f07230291.jpg

    0赞 · 0采集
  • 大鹏丶Lee 2019-09-26

    1.创建document doc = DocumentHelper.createDocument();

    2.创建根节点rss doc.addelement

    3.添加根节点属性 rss.addAtribute("","");

    4.生成xml文件 通过XMLWriter生成;


    0赞 · 0采集
  • 不忘初心__ 2019-03-26

    设置输出格式/属性

    OutputFormat format = OutputFormat.createPrettyPrint();
    //format.setEnconding("GBK");
    new XMLWriter();//将format作为参数传入


    0赞 · 0采集
  • CLSTZH 2018-07-29

    设置生成xml的格式:OutputFormat format=OutputFormat.createPrettyPrint();

    设置编码:format.setEncoding(String encoding);

    可在生成xml文件时加入格式:XMLWriter writer=new XMLWriter(new FileOutputStream(new File(String fileName)),format);

    0赞 · 0采集
  • BirdOfV 2018-05-22

    private void createXML() {
     //1.创建document对象,代表整个xml文档
     Document document = DocumentHelper.createDocument();
     //2.创建根节点
     Element rss = document.addElement("rss");
     //3.向rss节点中添加version属性
     rss.addAttribute("version", "2.0");
     //4.生成子节点及节点内容
     Element channel = rss.addElement("channel");
     Element title = channel.addElement("title");
     title.setText("国内最新新闻");
     //5.设置生成xml的格式
     OutputFormat format = OutputFormat.createPrettyPrint();
     format.setEncoding("GBK");
     //6.生成xml文件
     File file = new File("rssnews.xml");
     XMLWriter writer;
     try {
      writer = new XMLWriter(new FileOutputStream(file),format);
      writer.write(document);
      writer.close();
     } catch (IOException e) {
      e.printStackTrace();
     }
    }

    0赞 · 1采集
  • qq_新月古城_0 2018-01-17
    //4.生成子节点及节点内容 Element channel = rss.addElement("channel"); Element title = channel.addElement("title"); title.setText("国内最新新闻"); //5.设置生成xml的格式 OutputFormat format = OutputFormat.createPrettyPrint();//自动换行和缩进 format.setEncoding("GBK"); //6.生成xml文件 File file = new File("rssnews.xml"); try { XMLWriter writer = new XMLWriter(new FileOutputStream(file),format); writer.write(document); writer.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
    截图
    0赞 · 0采集
  • 690017359 2017-11-23
    //4.生成子节点及节点内容 Element channel = rss.addElement("channel"); Element title = channel.addElement("title"); title.setText("国内最新新闻"); //5.设置生成xml的格式 OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("GBK"); //6.生成xml文件 File file = new File("rssnews.xml"); try { XMLWriter writer = new XMLWriter(new FileOutputStream(file),format); writer.write(document); writer.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
    0赞 · 0采集
  • 世界第一大剑豪 2017-07-21
    OutputFormat.createPrettyPrint();自动完成缩进和换行
    0赞 · 0采集
  • 慕粉5101576 2017-07-20
    使用DOM4J生成XML文件中节点以及节点内容的步骤 1,使用根节点对象得到子节点对象 Element ele1 = ele.addElement("String"); 2,设置子节点文本内容 ele1.setText("String"); 3,设置生成的XML文档的格式 OutputFormat format = OutputFormat.creatPrettyPrint(); 这个format对象默认为标准格式,需要其他格式可以调用该对象的其他方法如: format.setEncoding("GBK"); 4,将设置同步到XML文档 Writer write = new Writer(new FileOutputStream(file),format);
    0赞 · 0采集
  • 爱笑的毛毛虫 2017-04-29
    OutputFormat.createPrettyPrint();自动完成缩进和换行 使用DOM4J生成XML文件中节点以及节点内容的步骤 1,使用根节点对象得到子节点对象 Element ele1 = ele.addElement("String"); 2,设置子节点文本内容 ele1.setText("String"); 3,设置生成的XML文档的格式 OutputFormat format = OutputFormat.creatPrettyPrint(); 这个format对象默认为标准格式,需要其他格式可以调用该对象的其他方法如: format.setEncoding("GBK"); 4,将设置同步到XML文档 Writer write = new Writer(new FileOutputStream(file),format);
    0赞 · 0采集
  • 最後的最後_ 2017-04-17
    !!!
    截图
    0赞 · 0采集
  • 最後的最後_ 2017-04-17
    !!!
    截图
    0赞 · 0采集
  • 最後的最後_ 2017-04-17
    !!!!
    截图
    0赞 · 0采集
  • 紫色郁金香song 2017-03-01
    rss是什么
    截图
    0赞 · 0采集
  • 请说实话 2017-02-26
    你们试过那代码缩进吗?为啥我的会缩进失败?creatPrettyPrint()就是没缩进,也是无语?用imooc的源码也不行的
    0赞 · 0采集
  • 滕玉龙 2017-02-20
    public void createXML() { // 1.创建document对象,代表整个xml文档 Document document = DocumentHelper.createDocument(); // 2.创建根节点rss Element rss = document.addElement("rss"); // 3.向rss节点中添加version属性 rss.addAttribute("version", "2.0"); //4.生成子节点及内容 Element channel = rss.addElement("channel"); Element title = channel.addElement("title"); title.setText("国内最新新闻"); //5.设置生成xml的格式 OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("GBK"); // 6.生成xml文件 File file = new File("rssnews.xml"); XMLWriter writer; try { writer = new XMLWriter(new FileOutputStream(file),format); writer.write(document); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { new DOM4JTest().createXML(); 运行结果: <?xml version="1.0" encoding="GBK"?> <rss version="2.0"> <channel> <title>国内最新新闻</title> </channel> </rss>
    截图
    0赞 · 1采集
  • 滕玉龙 2017-02-20
    <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"> <channel> <title>国内最新新闻</title> </channel> </rss>
    截图
    0赞 · 1采集
  • 滕玉龙 2017-02-20
    public void createXML() { // 1.创建document对象,代表整个xml文档 Document document = DocumentHelper.createDocument(); // 2.创建根节点rss Element rss = document.addElement("rss"); // 3.向rss节点中添加version属性 rss.addAttribute("version", "2.0"); //4.生成子节点及内容 Element channel = rss.addElement("channel"); Element title = channel.addElement("title"); title.setText("国内最新新闻"); // 5.生成xml文件 File file = new File("rssnews.xml"); XMLWriter writer; 运行结果: <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"><channel><title>国内最新新闻</title></channel></rss>
    截图
    0赞 · 1采集
  • 滕玉龙 2017-02-19
    看到1:25
    截图
    0赞 · 1采集
  • 滕玉龙 2017-02-19
    使用DOM4J生成XML文件中节点以及节点内容的步骤 1,使用根节点对象得到子节点对象 Element ele1 = ele.addElement("String"); 2,设置子节点文本内容 ele1.setText("String"); 3,设置生成的XML文档的格式 OutputFormat format = OutputFormat.creatPrettyPrint(); 这个format对象默认为标准格式,需要其他格式可以调用该对象的其他方法如: format.setEncoding("GBK"); 4,将设置同步到XML文档 Writer write = new Writer(new FileOutputStream(file),format); 很明了!
    0赞 · 3采集
  • lx他哥 2017-02-13
    使用DOM4J生成XML文件中节点以及节点内容的步骤 1,使用根节点对象得到子节点对象 Element ele1 = ele.addElement("String"); 2,设置子节点文本内容 ele1.setText("String"); 3,设置生成的XML文档的格式 OutputFormat format = OutputFormat.creatPrettyPrint(); 这个format对象默认为标准格式,需要其他格式可以调用该对象的其他方法如: format.setEncoding("GBK"); 4,将设置同步到XML文档 Writer write = new Writer(new FileOutputStream(file),format);
    截图
    0赞 · 0采集
  • 没死接着学 2017-01-26
    DOM4J生成子节点及节点内容: Element类中的方法: .addElement(子节点名称) 生成子节点 .setText(节点内容) 添加节点内容 设置生成xml的格式: OutputFormat format = OutputFormat.createPrettyPrint(); 在XMLWriter中添加该参数 可通过format设置xml的各种性质。
    0赞 · 0采集
  • qq_初时模样_04350133 2017-01-06
    使用DOM4J生成XML文件中节点以及节点内容的步骤 1,使用根节点对象得到子节点对象 Element ele1 = ele.addElement("String"); 2,设置子节点文本内容 ele1.setText("String"); 3,设置生成的XML文档的格式 OutputFormat format = OutputFormat.creatPrettyPrint(); 这个format对象默认为标准格式,需要其他格式可以调用该对象的其他方法如: format.setEncoding("GBK"); 4,将设置同步到XML文档 Writer write = new Writer(new FileOutputStream(file),format);
    0赞 · 1采集
  • 章鱼锐锐4416831 2016-12-23
    //4.生成子节点及节点内容 Element channel = rss.addElement("channel"); Element title = channel.addElement("title"); title.setText("<![CDATA[上海移动互联网产业促进中心正式揭牌 ]]>"); //5.设置生成xml的格式 OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("GBK"); //6.生成xml文件 File file = new File("rssnews.xml"); XMLWriter writer; try { writer = new XMLWriter(new FileOutputStream(file), format); //设置是否转义,默认值是true,代表转义 writer.setEscapeText(false); writer.write(document); writer.close(); } catch (IOException e) { e.printStackTrace(); }
    0赞 · 0采集
  • 小明小红小张丶 2016-12-13
    OutputFormat.createPrettyPrint 生成漂亮的 格式文本及其换行
    0赞 · 0采集
  • 不合格的程序猿 2016-10-21
    //Dom4j生成子节点和内容 private void createXML() { Document document = DocumentHelper.createDocument(); Element rss = document.addElement("rss"); rss.addAttribute("version", "2.0"); Element channel = rss.addElement("channel"); Element title = rss.addElement("title"); title.setText("国内最新新闻"); OutputFormat format = OutputFormat.createPrettyPrint(); File file =new File("rssnews.xml"); XMLWriter writer; try { writer = new XMLWriter(new FileOutputStream(file),format); writer.write(document); writer.close(); }catch (IOException e) { e.printStackTrace(); } }
    0赞 · 0采集
  • 慕粉3863764 2016-10-16
    1、设置子节点及节点内容: a.addElement("b");//在节点a下面建立新的子节点b; b.setText("...");//在节点b中添加文本内容 2、设置生成的xml文件的格式: 通过OutputFormat类来实现:OutputFormat format=OutputFormat.createPrettyPrint(); createPrettyPrint()方法不需主动设置就可实现自动换行缩进 format.setEncoding("GBK");//设置生成的XML文件的编码格式 设置完成后与xml文件关联的方法: 在建立XMLWriter对象的时候在构造方法中关联。
    截图
    0赞 · 0采集
  • 慕妹9026057 2016-09-20
    使用DOM4J生成XML文件中节点以及节点内容的步骤 1,使用根节点对象得到子节点对象 Element ele1 = ele.addElement("String"); 2,设置子节点文本内容 ele1.setText("String"); 3,设置生成的XML文档的格式 OutputFormat format = OutputFormat.creatPrettyPrint(); 这个format对象默认为标准格式,需要其他格式可以调用该对象的其他方法如: format.setEncoding("GBK"); 4,将设置同步到XML文档 Writer write = new Writer(new FileOutputStream(file),format);
    0赞 · 1采集
  • HCGKBOY 2016-09-14
    换行
    截图
    0赞 · 0采集
  • HCGKBOY 2016-09-14
    dom4j
    截图
    0赞 · 0采集
数据加载中...
开始学习 免费