1 DOM文档原始解析
主要使用了javax.xml.parser包中的
- javax.xml.parsers.DocumentBuilder
- javax.xml.parsers.DocumentBuilderFactory
和DOM文档的定义:org.w3c.dom包
上述的org.xml.sax.
XMLReader替代了org.xml.sax.parser 所以XMLReader才是名副其实的Parser
- org.w3c.dom.NamedNodeMap
- org.w3c.dom.NameList
- org.w3c.dom.Node
- org.w3c.dom.Attr
- org.w3c.dom.CharacterData
- org.w3c.dom.Comment
- org.w3c.dom.Text
- org.w3c.dom.CDATASection
- org.w3c.dom.Document
- org.w3c.dom.DocumentFragment
- org.w3c.dom.DocumentType
- org.w3c.dom.Element
- org.w3c.dom.Entity
- org.w3c.dom.EntityReference
- org.w3c.dom.Notation
- org.w3c.dom.ProcessingInstruction
- org.w3c.dom.NodeList
由于原始解析寻找节点困难,故引入了XPath
类分层结构
-
- javax.xml.xpath.XPathConstants
- javax.xml.xpath.XPathFactory
接口分层结构
- javax.xml.xpath.XPath
- javax.xml.xpath.XPathExpression
- javax.xml.xpath.XPathFunction
- javax.xml.xpath.XPathFunctionResolver
- javax.xml.xpath.XPathVariableResolver
2 SAX解析方法
主要使用了javax.xml.parser包中的
- javax.xml.parsers.SAXParser
- javax.xml.parsers.SAXParserFactory
类分层结构
- java.lang.Object
- org.xml.sax.HandlerBase (implements org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler)
- org.xml.sax.InputSource
- java.lang.Throwable (implements java.io.Serializable)
- java.lang.Exception
- org.xml.sax.SAXException
- org.xml.sax.SAXNotRecognizedException
- org.xml.sax.SAXNotSupportedException
- org.xml.sax.SAXParseException
- org.xml.sax.SAXException
- java.lang.Exception
接口分层结构
- org.xml.sax.AttributeList
- org.xml.sax.Attributes
- org.xml.sax.ContentHandler
- org.xml.sax.DocumentHandler
- org.xml.sax.DTDHandler
- org.xml.sax.EntityResolver
- org.xml.sax.ErrorHandler
- org.xml.sax.Locator
- org.xml.sax.Parser
- org.xml.sax.XMLReader
- org.xml.sax.XMLFilter
类分层结构
- java.lang.Object
- org.xml.sax.helpers.AttributeListImpl (implements org.xml.sax.AttributeList)
- org.xml.sax.helpers.AttributesImpl (implements org.xml.sax.Attributes)
- org.xml.sax.helpers.DefaultHandler (implements org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler)
- org.xml.sax.helpers.LocatorImpl (implements org.xml.sax.Locator)
- org.xml.sax.helpers.NamespaceSupport
- org.xml.sax.helpers.ParserAdapter (implements org.xml.sax.DocumentHandler, org.xml.sax.XMLReader)
- org.xml.sax.helpers.ParserFactory
- org.xml.sax.helpers.XMLFilterImpl (implements org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter)
- org.xml.sax.helpers.XMLReaderAdapter (implements org.xml.sax.ContentHandler, org.xml.sax.Parser)
- org.xml.sax.helpers.XMLReaderFactory
3StAX方式
StAX是以流的形式来解析XML文档(XMLStreamerReader),另外也可以事件的形式来解析(
XMLEventFactory
和XMLEventReader
)
类分层结构
- java.lang.Object
- java.lang.Throwable (implements java.io.Serializable)
- java.lang.Error
- javax.xml.stream.FactoryConfigurationError
- java.lang.Exception
- javax.xml.stream.XMLStreamException
- java.lang.Error
- javax.xml.stream.XMLEventFactory
- javax.xml.stream.XMLInputFactory
- javax.xml.stream.XMLOutputFactory
- java.lang.Throwable (implements java.io.Serializable)
接口分层结构
- javax.xml.stream.EventFilter
- java.util.Iterator<E>
- javax.xml.stream.XMLEventReader
- javax.xml.stream.Location
- javax.xml.stream.StreamFilter
- javax.xml.stream.util.XMLEventConsumer
- javax.xml.stream.XMLEventWriter
- javax.xml.stream.XMLReporter
- javax.xml.stream.XMLResolver
- javax.xml.stream.XMLStreamConstants
- javax.xml.stream.XMLStreamReader
- javax.xml.stream.XMLStreamWriter
另外,StAX以流的形式 不仅可以读,还可以写(XMLStreamWriter和XMLEventWriter),这就给写XML提供了除DOM方式的另一种方式。
4 transform方式
类分层结构
- java.lang.Object
- javax.xml.transform.OutputKeys
- java.lang.Throwable (implements java.io.Serializable)
- java.lang.Error
- javax.xml.transform.TransformerFactoryConfigurationError
- java.lang.Exception
- javax.xml.transform.TransformerException
- javax.xml.transform.TransformerConfigurationException
- javax.xml.transform.TransformerException
- java.lang.Error
- javax.xml.transform.Transformer
- javax.xml.transform.TransformerFactory
接口分层结构
- javax.xml.transform.ErrorListener
- javax.xml.transform.Result
- javax.xml.transform.Source
- javax.xml.transform.SourceLocator
- javax.xml.transform.Templates
- javax.xml.transform.URIResolver
还有两个接口Result和Source接口,对应扩展出来DOM,SAX ,StAX,Stream对应的Result和Source。
注意查看Java核心教程2:高级特性 第二章 transformTest