zoukankan      html  css  js  c++  java
  • 用jdom解析xml文件时如何解决中文问题?如何解析?

    看如下代码,用编码方式加以解决
    package test;
    import java.io.*;
    public class DOMTest
    {
    private String inFile = "c:people.xml"
    private String outFile = "c:people.xml"
    public static void main(String args[])
    {
    new DOMTest();
    }
    public DOMTest()
    {
    try
    {
    javax.xml.parsers.DocumentBuilder builder =
    javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
    org.w3c.dom.Document doc = builder.newDocument();
    org.w3c.dom.Element root = doc.createElement("老师");
    org.w3c.dom.Element wang = doc.createElement("王");
    org.w3c.dom.Element liu = doc.createElement("刘");
    wang.appendChild(doc.createTextNode("我是王老师"));
    root.appendChild(wang);
    doc.appendChild(root);
    javax.xml.transform.Transformer transformer =
    javax.xml.transform.TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING, "gb2312");
    transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
    transformer.transform(new javax.xml.transform.dom.DOMSource(doc),
    new
    javax.xml.transform.stream.StreamResult(outFile));
    }
    catch (Exception e)
    {
    System.out.println (e.getMessage());
    }
    }
    }

  • 相关阅读:
    New Skateboard
    Mike and strings
    C语言异或运算在程序设计中的妙用
    快速排序
    贪心算法
    快速排序过程分析
    深度搜索C语言伪代码
    matlab 中“newff” 函数的参数设置
    一维小波分解与去噪重构
    matlab绘图(详细)(全面)
  • 原文地址:https://www.cnblogs.com/zhu998/p/14227113.html
Copyright © 2011-2022 走看看