com.nonesole.commonui.xmlparser
类 W3CXml

java.lang.Object
  继承者 com.nonesole.commonui.xmlparser.W3CXml

public class W3CXml
extends java.lang.Object

使用 org.w3c.* 中的类来创建一些方法。
xml工具包提供了由文件-〉Document对象、由Document对象到文件、由Document->String/StringBuffer/byte[] 类型、由String/StringBuffer/byte[]-〉Document类型的方法。

版本:
1.0 - build in 2008-03-04
作者:
JACK

构造函数摘要
W3CXml()
           
 
方法摘要
static org.w3c.dom.Document createDocument()
          创建一个新的DOM Document对象。
static javax.xml.parsers.DocumentBuilder createDocumentBuilder()
          创建 DocumentBuilder 对象。
static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node node, java.lang.String nodeName)
          获取指定名称节点的集合
static java.lang.String getNodes(org.w3c.dom.Node node, java.lang.String nodeName, int position, java.lang.String itemName)
          获取第一个指定名称节点的指定属性值
static org.w3c.dom.Node getRoot(org.w3c.dom.Document doc)
          获取根节点
static org.w3c.dom.Document loadFile(java.lang.String filePath)
          读取XML文件,返回Document对象
static byte[] parseToStream(org.w3c.dom.Document doc)
          将Documnet对象转换为byte[]字节数组
static org.w3c.dom.Document parseXmlDocument(byte[] xml)
          解析byte[]数组为Document对象。
static org.w3c.dom.Document parseXmlDocument(java.lang.StringBuffer xmlString)
          解析StringBuffer对象为Document对象.
static void saveFile(org.w3c.dom.Document doc, java.lang.String filePath)
          将Document对象保存为XML文件
static java.lang.String xmlDocumentToString(org.w3c.dom.Document doc)
          把Document转换为String对象
static java.lang.StringBuffer xmlDocumentToStringBuffer(org.w3c.dom.Document doc)
          把Document转换为StringBuffer对象
 
从类 java.lang.Object 继承的方法
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造函数详细信息

W3CXml

public W3CXml()
方法详细信息

createDocumentBuilder

public static javax.xml.parsers.DocumentBuilder createDocumentBuilder()
                                                               throws javax.xml.parsers.ParserConfigurationException
创建 DocumentBuilder 对象。

抛出:
javax.xml.parsers.ParserConfigurationException

parseXmlDocument

public static org.w3c.dom.Document parseXmlDocument(java.lang.StringBuffer xmlString)
                                             throws javax.xml.parsers.ParserConfigurationException,
                                                    org.xml.sax.SAXException,
                                                    java.io.IOException
解析StringBuffer对象为Document对象.

参数:
xmlString - - StringBuffer对象;
返回:
Document对象;
抛出:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

parseXmlDocument

public static org.w3c.dom.Document parseXmlDocument(byte[] xml)
                                             throws javax.xml.parsers.ParserConfigurationException,
                                                    org.xml.sax.SAXException,
                                                    java.io.IOException
解析byte[]数组为Document对象。

参数:
xml - - the byte[] array object;
返回:
Document Object;
抛出:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

createDocument

public static org.w3c.dom.Document createDocument()
                                           throws javax.xml.parsers.ParserConfigurationException
创建一个新的DOM Document对象。

返回:
DOM Document Object;
抛出:
javax.xml.parsers.ParserConfigurationException

xmlDocumentToString

public static java.lang.String xmlDocumentToString(org.w3c.dom.Document doc)
把Document转换为String对象

参数:
doc - Document对象
返回:
转化成功的String

xmlDocumentToStringBuffer

public static java.lang.StringBuffer xmlDocumentToStringBuffer(org.w3c.dom.Document doc)
把Document转换为StringBuffer对象

参数:
doc - Document对象
返回:
转化成功的StringBuffer

parseToStream

public static byte[] parseToStream(org.w3c.dom.Document doc)
将Documnet对象转换为byte[]字节数组

参数:
doc - Document对象
返回:
byte[] 字节数组对象

loadFile

public static org.w3c.dom.Document loadFile(java.lang.String filePath)
                                     throws java.lang.Exception
读取XML文件,返回Document对象

参数:
filePath - String
返回:
document Document对象
抛出:
java.lang.Exception

saveFile

public static void saveFile(org.w3c.dom.Document doc,
                            java.lang.String filePath)
                     throws java.lang.Exception
将Document对象保存为XML文件

参数:
doc - Doucument对象
filePath - 文件的路径
抛出:
java.lang.Exception

getRoot

public static org.w3c.dom.Node getRoot(org.w3c.dom.Document doc)
获取根节点

参数:
doc - Document对象
返回:
根节点

getNodes

public static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node node,
                                                        java.lang.String nodeName)
获取指定名称节点的集合

参数:
node - 父节点对象
nodeName - 指定子节点的名称
返回:
符合要求的子节点队列

getNodes

public static java.lang.String getNodes(org.w3c.dom.Node node,
                                        java.lang.String nodeName,
                                        int position,
                                        java.lang.String itemName)
获取第一个指定名称节点的指定属性值

参数:
node - 父节点对象
nodeName - 指定子节点的名称
position - 取同名称子节点的第position个子节点
itemName - 指定属性的名称
返回:
属性值