XML解析器.doc

上传人:j****9 文档编号:2275388 上传时间:2019-05-05 格式:DOC 页数:25 大小:339.50KB
下载 相关 举报
XML解析器.doc_第1页
第1页 / 共25页
XML解析器.doc_第2页
第2页 / 共25页
XML解析器.doc_第3页
第3页 / 共25页
XML解析器.doc_第4页
第4页 / 共25页
XML解析器.doc_第5页
第5页 / 共25页
点击查看更多>>
资源描述

1、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 的子集,是互

2、联网上交换数据的标准。XML 文件包含了数据对象和处理这些数据对象的程序的描述。XML 文件在被浏览器显示出来或其他应用程序使用之前,经过了以下几个步骤:解析、样式表格式化、转换、数据库访问等。XML 解析器完成第一步工作,它读取 XML 文件,生成语法树,审查文档结构,将结果传给应用程序。XML 解析器可以是验证解析器,用以检查文件是否有效,也可以是非验证解析器,仅为结构良好的文件进行检查。应用程序可使用 C、Java 或 Jscript、VBscript、ASP 等脚本语言,通过解析器接口对XML 文件中的元素、属性、实体和标记进行操作。常见的 XML 解析器:1. MSXML,微软的 X

3、ML 解析器,与 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 对 Xerce

4、s 的扩展。XML4j 的 API 分为 3 类:Public:包括 DOM1、DOM2 接口,SAX1、SAX2 接口Experimental:包括 DOM3 接口Internal:内部接口DOM 接口:整个 XML 文档被视为具有层次关系的节点树,所有的非根节点都是以一个根节点为祖先遗传下来。例如这段文件,Shady GroveAeolian Over the River, Charlie Dorian DOM 将其看作下面这棵树,当然“树“的观念只是逻辑上的,协议的实现可以采用各种方式。对树进行深度优先前序遍历即可重现文档。DOM 中每一种节点类型都有一个相应的接口。DOM 的节点类型有

5、:Document、Element、Attr、Text、CDATASection、EntityReference、Entity、ProcessingInstruction、 Comment、DocumentType 、DocumentFragment、Notation。节点的包容关系:Document Element, ProcessingInstruction, Comment, DocumentTypeElement Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReferenceAttr Text,

6、EntityReferenceTextCDATASectionEntityReference Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceEntity Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceProcessinfInstructionCommentDocumentTypeDocumentFragment Element, ProcessingInstruction, Comme

7、nt, Text, CDATASection, EntityReferenceNotationDOM1 由两部分组成:Core DOM 和 HTML DOM。Core DOM 进一步被划分为基础接口和扩展接口,所有解析器都必须实现基础接口,如果只对 HTML 文档进行操作,则不需要实现扩展接口。HTML DOM 对 HTML 文档所特有的对象和方法进行描述,可参见相关规范,此处不详述。基础接口:DOMException 接口:exception DOMException unsigned short code;/ ExceptionCodeconst unsigned short INDEX_

8、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 u

9、nsigned 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

10、 ;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

11、(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

12、);EntityReference createEntityReference(in DOMString name)raises(DOMException);NodeList getElementsByTagName(in DOMString tagname);Node 接口interface Node / NodeTypeconst unsigned short ELEMENT_NODE = 1;const unsigned short ATTRIBUTE_NODE = 2;const unsigned short TEXT_NODE = 3;const unsigned short CDA

13、TA_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

14、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;rea

15、donly 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

16、, 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 l

17、ong 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 : Nod

18、e 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 remo

19、veAttribute(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 接口:inte

20、rface 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)rai

21、ses(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(DOMExcep

22、tion);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 N

23、otation : 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 ;Proc

24、essingInstruction 接口:interface ProcessingInstruction : Node readonly attribute DOMString target;attribute DOMString data;DOM2 包括核心规范和遍历与漫游规范。DOM3 包括核心规范和抽象机制与存取规范。DOM2 和 DOM3 的核心规范基本保持 DOM1 的接口结构,增加了命名空间( namespace)概念,并对少数接口的属性和方法做了增删和修改。module domvaluetype DOMString sequence;typedef unsigned long l

25、ong 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;/ Exception

26、Codeconst 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_MODIF

27、ICATION_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;/ Introduce

28、d 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 DOMImplement

29、ationSource 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)ra

30、ises(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 / NodeTypeconst unsigned short EL

31、EMENT_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_

32、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;readonl

33、y 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

34、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(DOMExcepti

35、on);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 DOM

36、String 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;/ TreePositionconst unsigned short TREE_P

37、OSITION_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

38、 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);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 实用文档资料库 > 策划方案

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。