無線&移動互聯網技術研發

          換位思考·····
          posts - 19, comments - 53, trackbacks - 0, articles - 283
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          獲取XML的編碼

          Posted on 2009-12-27 01:01 Gavin.lee 閱讀(515) 評論(0)  編輯  收藏 所屬分類: xml doc 操作
          獲取xml的編碼:
          package com.Gavin.tools.xml;

          import java.io.FileInputStream;
          import java.io.FileNotFoundException;
          import java.io.IOException;
          import java.io.InputStream;

          import javax.xml.parsers.DocumentBuilder;
          import javax.xml.parsers.DocumentBuilderFactory;
          import javax.xml.parsers.ParserConfigurationException;

          import org.apache.xerces.dom.DocumentImpl;
          import org.dom4j.Document;
          import org.dom4j.DocumentException;
          import org.dom4j.DocumentHelper;
          import org.xml.sax.SAXException;

          public class GetXmlEncoding {

              
          public static void main(String args[]) {
                  
          try {
                      
          /*DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
                      DocumentBuilder builder = factory.newDocumentBuilder(); 
                      InputStream in = new FileInputStream(args[0]); 
                      DocumentImpl docI = (DocumentImpl)builder.parse(in); 
                      System.out.println(docI.getXmlEncoding()); 
          */

              
                      
          //
                      String xml = "<?xml version='1.0' encoding='iso-8859-1'?><Message>Hi there</Message>"
                      Document doc 
          = DocumentHelper.parseText(xml); 
                      System.out.println(
          "The encoding is " + doc.getXMLEncoding()); 
                      System.out.println(
          "As XML: " + doc.asXML()); 
                  
          //}catch (ParserConfigurationException e) {
                  
          //    e.printStackTrace();
                  
          //} catch (FileNotFoundException e) {
                  
          //    e.printStackTrace();
                  }
           catch (DocumentException e) {
                      e.printStackTrace();
                  
          //} catch (SAXException e) {
                  
          //    e.printStackTrace();
                  
          //} catch (IOException e) {
                  
          //    e.printStackTrace();
                  }

              }

          }

          主站蜘蛛池模板: 屯留县| 靖远县| 探索| 化德县| 积石山| 康马县| 盐山县| 弋阳县| 渝中区| 延庆县| 潜江市| 乌鲁木齐市| 望谟县| 嘉峪关市| 乐清市| 咸宁市| 年辖:市辖区| 鄂尔多斯市| 崇仁县| 广昌县| 依兰县| 任丘市| 灵台县| 绥阳县| 宝兴县| 罗山县| 虎林市| 阳泉市| 西充县| 濮阳县| 宿州市| 湘西| 高平市| 伊宁县| 资源县| 抚远县| 松滋市| 广河县| 蛟河市| 兴化市| 分宜县|