《XML解析器》word版.doc_第1页
《XML解析器》word版.doc_第2页
《XML解析器》word版.doc_第3页
《XML解析器》word版.doc_第4页
《XML解析器》word版.doc_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

XML解析器接口缩略语XML eXtensible Markup Language 可扩展的置标语言DOM Document Object Model,文档对象模型SAX Simple API for XML,简单的XML APIJAXP Java API for XML Processing XML的Java接口DTD Document Type Definition,文档对象定义XSL Extensible Stylesheet Language,可扩展样式语言可扩展标记语言XML(eXtensible Markup Language)是标准通用标记语言SGML的子集,是互联网上交换数据的标准。XML文件包含了数据对象和处理这些数据对象的程序的描述。XML文件在被浏览器显示出来或其他应用程序使用之前,经过了以下几个步骤:解析、样式表格式化、转换、数据库访问等。XML解析器完成第一步工作,它读取XML文件,生成语法树,审查文档结构,将结果传给应用程序。XML解析器可以是验证解析器,用以检查文件是否有效,也可以是非验证解析器,仅为结构良好的文件进行检查。应用程序可使用C、Java或Jscript、VBscript、ASP等脚本语言,通过解析器接口对XML文件中的元素、属性、实体和标记进行操作。常见的XML解析器:1. MSXML,微软的XML解析器,与W3C规范不完全兼容。2. Xerces,开放源码组织提供,实现Xerces本地接口XNI,支持的标准有:XML1.0、XML命名空间、DOM2(Core, Events, and Traversal and Range)、SAX2(Core, and Extension)、JAXP1.1、XML Schema 1.0(Structures and Datatypes)。Xerces有3个版本,分别用C+、java和perl实现。应用程序可以链接Xerces库,调用其接口访问XML文档。3 XML4j、XML4c,IBM对Xerces的扩展。XML4j的API分为3类:Public:包括DOM1、DOM2接口,SAX1、SAX2接口Experimental:包括DOM3接口Internal:内部接口DOM接口:整个XML文档被视为具有层次关系的节点树,所有的非根节点都是以一个根节点为祖先遗传下来。例如这段文件, Shady Grove Aeolian Over the River, Charlie Dorian DOM将其看作下面这棵树,当然“树“的观念只是逻辑上的,协议的实现可以采用各种方式。对树进行深度优先前序遍历即可重现文档。DOM中每一种节点类型都有一个相应的接口。DOM的节点类型有:Document、Element、Attr、Text、CDATASection、EntityReference、Entity、ProcessingInstruction、Comment、DocumentType、DocumentFragment、Notation。节点的包容关系:DocumentElement, ProcessingInstruction, Comment, DocumentTypeElementElement, Text, Comment, ProcessingInstruction, CDATASection, EntityReferenceAttrText, EntityReferenceTextCDATASectionEntityReferenceElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceEntityElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceProcessinfInstructionCommentDocumentTypeDocumentFragmentElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceNotationDOM1由两部分组成:Core DOM和HTML DOM。Core DOM进一步被划分为基础接口和扩展接口,所有解析器都必须实现基础接口,如果只对HTML文档进行操作,则不需要实现扩展接口。HTML DOM对HTML文档所特有的对象和方法进行描述,可参见相关规范,此处不详述。基础接口:DOMException接口:exception DOMException unsigned short code;/ ExceptionCodeconst unsigned short INDEX_SIZE_ERR = 1;const unsigned short DOMSTRING_SIZE_ERR = 2;const unsigned short HIERARCHY_REQUEST_ERR = 3;const unsigned short WRONG_DOCUMENT_ERR = 4;const unsigned short INVALID_CHARACTER_ERR = 5;const unsigned short NO_DATA_ALLOWED_ERR = 6;const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;const unsigned short NOT_FOUND_ERR = 8;const unsigned short NOT_SUPPORTED_ERR = 9;const unsigned short INUSE_ATTRIBUTE_ERR = 10;DOMImplementation接口:由用户实现interface DOMImplementation boolean hasFeature(in DOMString feature, in DOMString version);DocumentFragment接口:用于子树移动和插入interface DocumentFragment : Node ;Document接口:interface Document : Node readonly attribute DocumentType doctype; readonly attribute DOMImplementation implementation; readonly attribute Element documentElement; Element createElement(in DOMString tagName) raises(DOMException); DocumentFragment createDocumentFragment(); Text createTextNode(in DOMString data); Comment createComment(in DOMString data); CDATASection createCDATASection(in DOMString data) raises(DOMException); ProcessingInstruction createProcessingInstruction(in DOMString target, in DOMString data) raises(DOMException); Attr createAttribute(in DOMString name) raises(DOMException); EntityReference createEntityReference(in DOMString name) raises(DOMException); NodeList getElementsByTagName(in DOMString tagname);Node接口interface Node / NodeType const unsigned short ELEMENT_NODE = 1; const unsigned short ATTRIBUTE_NODE = 2; const unsigned short TEXT_NODE = 3; const unsigned short CDATA_SECTION_NODE = 4; const unsigned short ENTITY_REFERENCE_NODE = 5; const unsigned short ENTITY_NODE = 6; const unsigned short PROCESSING_INSTRUCTION_NODE = 7; const unsigned short COMMENT_NODE = 8; const unsigned short DOCUMENT_NODE = 9; const unsigned short DOCUMENT_TYPE_NODE = 10; const unsigned short DOCUMENT_FRAGMENT_NODE = 11; const unsigned short NOTATION_NODE = 12; readonly attribute DOMString nodeName; readonly attribute DOMString nodeValue; readonly attribute unsigned short nodeType; readonly attribute Node parentNode; readonly attribute NodeList childNodes; readonly attribute Node firstChild; readonly attribute Node lastChild; readonly attribute Node previousSibling; readonly attribute Node nextSibling; readonly attribute NamedNodeMap attributes; readonly attribute Document ownerDocument; Node insertBefore(in Node newChild, in Node refChild) raises(DOMException); Node replaceChild(in Node newChild, in Node oldChild) raises(DOMException); Node removeChild(in Node oldChild) raises(DOMException); Node appendChild(in Node newChild) raises(DOMException); boolean hasChildNodes(); Node cloneNode(in boolean deep);NodeList接口:interface NodeList Node item(in unsigned long index); readonly attribute unsigned long length;NamedNodeMap接口:interface NamedNodeMap Node getNamedItem(in DOMString name); Node setNamedItem(in Node arg) raises(DOMException); Node removeNamedItem(in DOMString name) raises(DOMException); Node item(in unsigned long index); readonly attribute unsigned long length;Attr接口:interface Attr : Node readonly attribute DOMString name; readonly attribute boolean specified; attribute DOMString value;Element接口:interface Element : Node readonly attribute DOMString tagName; DOMString getAttribute(in DOMString name); void setAttribute(in DOMString name, in DOMString value) raises(DOMException); void removeAttribute(in DOMString name) raises(DOMException); Attr getAttributeNode(in DOMString name); Attr setAttributeNode(in Attr newAttr) raises(DOMException); Attr removeAttributeNode(in Attr oldAttr) raises(DOMException); NodeList getElementsByTagName(in DOMString name); void normalize();CharacterData接口:interface CharacterData : Node attribute DOMString data; readonly attribute unsigned long length; DOMString substringData(in unsigned long offset, in unsigned long count) raises(DOMException); void appendData(in DOMString arg) raises(DOMException); void insertData(in unsigned long offset, in DOMString arg) raises(DOMException); void deleteData(in unsigned long offset, in unsigned long count) raises(DOMException); void replaceData(in unsigned long offset, in unsigned long count, in DOMString arg) raises(DOMException);Text接口:interface Text : CharacterData Text splitText(in unsigned long offset) raises(DOMException);Comment接口:interface Comment : CharacterData ;扩展接口:CDATASection接口:标记以定界的CDATA段interface CDATASection : Text ;DocumentType接口:interface DocumentType : Node readonly attribute DOMString name; readonly attribute NamedNodeMap entities; readonly attribute NamedNodeMap notations;Node接口:interface Notation : Node readonly attribute DOMString publicId; readonly attribute DOMString systemId;Entity接口:interface Entity : Node readonly attribute DOMString publicId; readonly attribute DOMString systemId; readonly attribute DOMString notationName;EntityReference接口:interface EntityReference : Node ;ProcessingInstruction接口:interface ProcessingInstruction : Node readonly attribute DOMString target; attribute DOMString data;DOM2包括核心规范和遍历与漫游规范。DOM3包括核心规范和抽象机制与存取规范。DOM2和DOM3的核心规范基本保持DOM1的接口结构,增加了命名空间(namespace)概念,并对少数接口的属性和方法做了增删和修改。module dom valuetype DOMString sequence; typedef unsigned long long DOMTimeStamp; typedef Object DOMUserData; typedef Object DOMObject; interface DOMImplementation; interface DocumentType; interface Document; interface NodeList; interface NamedNodeMap; interface UserDataHandler; interface Element; interface DOMLocator; exception DOMException unsigned short code; ; / ExceptionCode const unsigned short INDEX_SIZE_ERR = 1; const unsigned short DOMSTRING_SIZE_ERR = 2; const unsigned short HIERARCHY_REQUEST_ERR = 3; const unsigned short WRONG_DOCUMENT_ERR = 4; const unsigned short INVALID_CHARACTER_ERR= 5; const unsigned short NO_DATA_ALLOWED_ERR = 6; const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7; const unsigned short NOT_FOUND_ERR = 8; const unsigned short NOT_SUPPORTED_ERR = 9; const unsigned short INUSE_ATTRIBUTE_ERR = 10; / Introduced in DOM Level 2: const unsigned short INVALID_STATE_ERR = 11; / Introduced in DOM Level 2: const unsigned short SYNTAX_ERR = 12; / Introduced in DOM Level 2: const unsigned short INVALID_MODIFICATION_ERR = 13; / Introduced in DOM Level 2: const unsigned short NAMESPACE_ERR = 14; / Introduced in DOM Level 2: const unsigned short INVALID_ACCESS_ERR = 15; / Introduced in DOM Level 3: const unsigned short VALIDATION_ERR = 16; interface DOMImplementationSource DOMImplementation getDOMImplementation(in DOMString features); ; interface DOMImplementation boolean hasFeature(in DOMString feature, in DOMString version); / Introduced in DOM Level 2: DocumentType createDocumentType(in DOMString qualifiedName, in DOMString publicId, in DOMString systemId) raises(DOMException); / Introduced in DOM Level 2: Document createDocument(in DOMString namespaceURI, in DOMString qualifiedName, in DocumentType doctype) raises(DOMException); / Introduced in DOM Level 3: DOMImplementation getInterface(in DOMString feature); ; interface Node / NodeType const unsigned short ELEMENT_NODE = 1; const unsigned short ATTRIBUTE_NODE = 2; const unsigned short TEXT_NODE = 3; const unsigned short CDATA_SECTION_NODE = 4; const unsigned short ENTITY_REFERENCE_NODE = 5; const unsigned short ENTITY_NODE = 6; const unsigned short PROCESSING_INSTRUCTION_NODE = 7; const unsigned short COMMENT_NODE = 8; const unsigned short DOCUMENT_NODE = 9; const unsigned short DOCUMENT_TYPE_NODE = 10; const unsigned short DOCUMENT_FRAGMENT_NODE = 11; const unsigned short NOTATION_NODE = 12; readonly attribute DOMString nodeName; attribute DOMString nodeValue; readonly attribute unsigned short nodeType; readonly attribute Node parentNode; readonly attribute NodeList childNodes; readonly attribute Node firstChild; readonly attribute Node lastChild; readonly attribute Node previousSibling; readonly attribute Node nextSibling; readonly attribute NamedNodeMap attributes; / Modified in DOM Level 2: readonly attribute Document ownerDocument; / Modified in DOM Level 3: Node insertBefore(in Node newChild, in Node refChild) raises(DOMException); / Modified in DOM Level 3: Node replaceChild(in Node newChild, in Node oldChild) raises(DOMException); / Modified in DOM Level 3: Node removeChild(in Node oldChild) raises(DOMException); Node appendChild(in Node newChild) raises(DOMException); boolean hasChildNodes(); Node cloneNode(in boolean deep); / Modified in DOM Level 2: void normalize(); / Introduced in DOM Level 2: boolean isSupported(in DOMString feature, in DOMString version); / Introduced in DOM Level 2: readonly attribute DOMString namespaceURI; / Introduced in DOM Level 2: attribute DOMString prefix; / Introduced in DOM Level 2: readonly attribute DOMString localName; / Introduced in DOM Level 2: boolean hasAttributes(); / Introduced in DOM Level 3: readonly attribute DOMString baseURI; / TreePosition const unsigned short TREE_POSITION_PRECEDING = 0x01; const unsigned short TREE_POSITION_FOLLOWING = 0x02; const unsigned short TREE_POSITION_ANCESTOR = 0x04; const unsigned short TREE_POSITION_DESCENDANT = 0x08; const unsigned short TREE_POSITION_EQUIVALENT = 0x10; const unsigned short TREE_POSITION_SAME_NODE = 0x20; const unsigned short TREE_POSITION_DISCONNECTED = 0x00; / Introduced in DOM Level 3: unsigned short compareTreePosition(in Node other); / Introduced in DOM Level 3: attribute DOMString textContent; / Introduced in DOM Level 3: boolean isSameNode(in Node other); / Introduced in DOM Level 3: DOMString lookupNamespacePrefix(in DOMString namespaceURI, in boolean useDefault); / Introduced in DOM Level 3: boolean isDefaultNamespace(in DOMString namespaceURI); / Introduced in DOM Level 3: DOMString lookupNamespaceURI(in DOMString prefix); / Introduced in DOM Level 3: boolean isEqualNode(in Node arg); / Introduced in DOM Level 3: Node getInterface(in DOMString feature); / Introduced in DOM Level 3: DOMUserData setUserData(in DOMString key, in DOMUserData data, in UserDataHandler handler); / Introduced in DOM Level 3: DOMUserData getUserData(in DOMString key); ; interface NodeList Node item(in unsigned long index); readonly attribute unsigned long length; ; interface NamedNodeMap Node getNamedItem(in DOMString name); Node setNamedItem(in Node arg) raises(DOMException); Node removeNamedItem(in DOMString name) raises(DOMException); Node item(in unsigned long index); readonly attribute unsigned long length; / Introduced in DOM Level 2: Node getNamedItem

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论