Java and XML (1) foundation

xiaoxiao2021-03-06  52

JAXP API - embedded different interpreter SAX interpreter DOM interpreter XSL converter

Javax.xml.Parsers Load XML document class: DocumentBuild0BuildRfactorySaxParsersaxParserFactory ===================================== SAX API

SAX XML Interpretation: Apache's Xerces or Crimson

Processing the interface of the XML document: ContentHandlerentityResolvererrohandlerdtdhandler

DECLHANDLERLEXICALHANDLER ====================================== DOM API

Two DOM standards: DOM Level1 Dom Level 2 Core

Node Node-Node Type Interface Hierarchy Roots. Document-Tree Structure The root Element-XML Element Text-Element Tread Attr - Elements of Element-Element CDATA Sectionn-CDataNodelist-child Node Collection Processinginstruction-Command Comment - Contains Information DocumentFragment-Document's reduction version of Document, for the tree The subset of the mobile node documenttype-document type definition. Entity-DTD Entity Tag EntityReference-XML Document Reference NOTATION-DTD symbol tag

Read the X M l document from the program basically has three ways: 1 Put X M L Just when doing a file, then pick the label yourself. This is a hacker method, we do not recommend this way. You will soon discover all special circumstances (including different character codes, exception agreed, internal and external entities, default attributes, etc.) more than imagination; you may not correctly handle all special circumstances, so Your program will receive a very specific XML document, but you can't handle it correctly. To avoid this idea: The XML parser does not seem to be expensive (most of which is free). 2 You can use the parser to analyze the document and create an expression of the document content in memory: The parser passes the output to the document object model, namely DOM. This program can be traversed from the top of the tree, and the required information is found according to the reference from a tree unit to another. 3 can also read the document with a parser, telling the label it discovers when the parser discovers the label. For example, it will inform it when a start tag is discovered, when some feature data, and when a end tag is discovered. This is called an event-driven interface because the parser tells the application that it has a meaningful event. If this is the interface you need, you can use SAX.

SAX is read-only DOM to read documents from an XML original file, or create and modify documents in memory. In contrast, SAX is used to read an XML document rather than writing documents.

转载请注明原文地址:https://www.9cbs.com/read-59656.html

New Post(0)