




已阅读5页,还剩23页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
XMLDOM属性列表The Microsoft XML ParserTo create an XML Document object with JavaScript, use the following code:var xmlDoc=new ActiveXObject(Microsoft.XMLDOM)xmlDoc.appendChild(xmlDoc.createElement(root)XML Parser in Mozilla BrowsersPlain XML documents are displayed in a tree-like structure in Mozilla (just like IE).Mozilla also supports parsing of XML data that resides in a file, using JavaScript. The parsed data can be displayed as HTML.To create an XML Document object with JavaScript in Mozilla, use the following code:var xmlDoc=document.implementation.createDocument(ns,root,null)The first parameter, ns, defines the namespace used for the XML document. The second parameter, root, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.Loading an XML File Into the ParserThe following code loads an existing XML document (note.xml) into the XML parser:var xmlDoc=new ActiveXObject(Microsoft.XMLDOM)xmlDoc.async=falsexmlDoc.load(note.xml)./ie和firefox都支持load,firefox不支持loadXML(string text)The first line of the script creates an instance of the Microsoft XML parser. The third line tells the parser to load an XML document called note.xml. The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.Accessing XML Elements by NameAddressing elements by number is NOT the preferred way to extract elements from XML documents. Using names is a better way:function loadXML()var xmlDoc=new ActiveXObject(Microsoft.XMLDOM)xmlDoc.async=falsexmlDoc.load(note.xml)/注意firefox的load(note.xml)并不会读该文件,须要给fox增加loadXML()涵数xmlDoc.getElementsByTagName(to).item(0).textxmlDoc.getElementsByTagName(from).item(0).textxmlDoc.getElementsByTagName(heading).item(0).textxmlDoc.getElementsByTagName(body).item(0).textImportant: To extract the text (Jani) from an element like this: Jani, the syntax is: getElementsByTagName(from).item(0).text, and NOT like this: getElementsByTagName(from).text. The reason for this is that the result returned from getElementsByTagName is an array of nodes, containing all nodes found within the XML document with the specified tag name (in this case from).The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, and Netscape 7.What is an HTTP Request?With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts might request pages, or send data to a server in the background.By using the XMLHttpRequest object, a web developer can change a page with data from the server after the page has loaded.Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Googles search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.Creating an XMLHttpRequest ObjectFor Mozilla, Firefox, Safari, and Netscape:var xmlhttp=new XMLHttpRequest()For Internet Explorer:var xmlhttp=new ActiveXObject(Microsoft.XMLHTTP)Examplevar xmlhttpfunction loadXMLDoc(url)/ code for Mozilla, etc.if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange=xmlhttpChange xmlhttp.open(GET,url,true) xmlhttp.send(null) / code for IEelse if (window.ActiveXObject) xmlhttp=new ActiveXObject(Microsoft.XMLHTTP) if (xmlhttp) xmlhttp.onreadystatechange=xmlhttpChange xmlhttp.open(GET,url,true) xmlhttp.send() function xmlhttpChange()/ if xmlhttp shows loadedif (xmlhttp.readyState=4) / if OK if (xmlhttp.status=200) / .some code here. else alert(Problem retrieving XML data) Why are we Using async in our Examples?Most of the examples here use the async mode (the third parameter of open() set to true).The async parameter specifies whether the request should be handled asynchronously or not. True means that script continues to run after the send() method, without waiting for a response from the server. false means that the script waits for a response before continuing script processing. By setting this parameter to false, you run the risk of having your script hang if there is a network or server problem, or if the request is long (the UI locks while the request is being made) a user may even see the Not Responding message. It is safer to send asynchronously and design your code around the onreadystatechange eventThe XMLHttpRequest Object ReferenceMethodsMethodDescriptionabort()Cancels the current requestgetAllResponseHeaders()Returns the complete set of http headers as a stringgetResponseHeader(headername)Returns the value of the specified http headeropen(method,URL,async,uname,pswd)Specifies the method, URL, and other optional attributes of a request The method parameter can have a value of GET, POST, or PUT (use GET when requesting data and use POST when sending data (especially if the length of the data is greater than 512 bytes.The URL parameter may be either a relative or complete URL.The async parameter specifies whether the request should be handled asynchronously or not. true means that script processing carries on after the send() method, without waiting for a response. false means that the script waits for a response before continuing script processingsend(content)Sends the requestsetRequestHeader(label,value)Adds a label/value pair to the http header to be sentPropertiesPropertyDescriptiononreadystatechangeAn event handler for an event that fires at every state changereadyStateReturns the state of the object: 0 = uninitialized1 = loading2 = loaded3 = interactive4 = complete responseTextReturns the response as a stringresponseXMLReturns the response as XML. This property returns an XML document object, which can be examined and parsed using W3C DOM node tree methods and propertiesstatusReturns the status as a number (e.g. 404 for Not Found or 200 for OK)statusTextReturns the status as a string (e.g. Not Found or OK)XML DOM Node TypesThe DOM StructureThe DOM presents a document as a hierarchy of node objects.The following table lists the different W3C node types, and which node types they may have as children:Node typeDescriptionChildrenDocumentRepresents the entire document (it is the root-node of the DOM tree)Element (max. one), ProcessingInstruction, Comment, DocumentTypeDocumentFragmentRepresents a lightweight Document object, which can hold a portion of a documentElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceDocumentTypeRepresents a list of the entities that are defined for the documentNoneEntityReferenceRepresents an entity referenceElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceElementRepresents an elementElement, Text, Comment, ProcessingInstruction, CDATASection, EntityReferenceAttrRepresents an attributeText, EntityReferenceProcessingInstructionRepresents a processing instructionNoneCommentRepresents a commentNoneTextRepresents textual content (character data) in an element or attributeNoneCDATASectionRepresents a block of text that may contains characters that would otherwise be treated as markupNoneEntityRepresents an entityElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReferenceNotationRepresents a notation declared in the DTDNoneNode Types - Return ValuesBelow is a list of what the nodeName and the nodeValue properties will return for each nodetype:Node typenodeName returnsnodeValue returnsDocument#documentnullDocumentFragment#document fragmentnullDocumentTypedoctype namenullEntityReferenceentity reference namenullElementelement namenullAttrattribute nameattribute valueProcessingInstructiontargetcontent of nodeComment#commentcomment textText#textcontent of nodeCDATASection#cdata-sectioncontent of nodeEntityentity namenullNotationnotation namenullNodeTypes - Named ConstantsNodeTypeNamed Constant1ELEMENT_NODE2ATTRIBUTE_NODE3TEXT_NODE4CDATA_SECTION_NODE5ENTITY_REFERENCE_NODE6ENTITY_NODE7PROCESSING_INSTRUCTION_NODE8COMMENT_NODE9DOCUMENT_NODE10DOCUMENT_TYPE_NODE11DOCUMENT_FRAGMENT_NODE12NOTATION_NODEXML DOM - The Attr ObjectThe Attr objectThe attr object represents an attribute of an element object.The attr objects properties and methods are described below:PropertiesPropertyDescriptionattributesReturns a NamedNodeMap that contains all attributes of a nodechildNodesReturns a node list that contains all children of a nodefirstChildReturns the first child node of a nodelastChildReturns the last child node of a nodenameReturns the name of the attributenextSiblingReturns the node immediately following a node. Two nodes are siblings if they have the same parent nodenodeNameReturns the name of the node (depending on the node type)nodeTypeReturns the node type as a numbernodeValueReturns the value of the nodeownerDocumentReturns the Document object of a node (returns the root node of the document)parentNodeReturns the parent node of a nodepreviousSiblingReturns the node immediately preceding a node. Two nodes are siblings if they have the same parent nodevalueReturns the value of the attributeMethodsMethodDescriptionappendChild(tagname)Appends a new child node to a nodecloneNode(boolean)Creates an exact clone node of a node. If the boolean parameter is set to true, the cloned node clones all the child nodes of the original node as wellhasChildNodes()Returns true if a node has child nodes. Otherwise it returns falseinsertBefore(newnode,refnode)Inserts a new node (newnode) before the existing node (refnode)removeChild(nodename)Removes the specified node and returns itreplaceChild(newnode,oldnode)Replaces the oldnode with the newnode, and returns the oldnodeThe CDATASection comment objectThe CDATASection object represents CDATASection nodes in a document. A CDATASection node is used to escape parts of text which normally would be recognized as markup.The CDATASection objects properties and methods are described below:PropertiesPropertyDescriptionattributesReturns a NamedNodeMap that contains all attributes of a nodechildNodesReturns a node list that contains all children of a nodedataReturns the data of the nodefirstChildReturns the first child node of a nodelastChildReturns the last child node of a nodelengthReturns the length of the data (in characters)nextSiblingReturns the node immediately following a node. Two nodes are siblings if they have the same parent nodenodeNameReturns the name of the node (depending on the node type)nodeTypeReturns the node type as a numbernodeValueReturns the value of the nodeownerDocumentReturns the Document object of a node (returns the root node of the document)parentNodeReturns the parent node of a nodepreviousSiblingReturns the node immediately preceding a node. Two nodes are siblings if they have the same parent nodeMethodsMethodDescriptionappendChild(tagname)Appends a new child node to a nodeappendData(strdata)Appends the specified string to the existing datacloneNode(boolean)Creates an exact clone node of a node. If the boolean parameter is set to true, the cloned node clones all the child nodes of the original node as welldeleteData(offset,count)Removes the specified range of characters from the datahasChildNodes()Returns true if a node has child nodes. Otherwise it returns falseinsertBefore(newnode,refnode)Inserts a new node (newnode) before the existing node (refnode)insertData(offset,string)Inserts the stringdata at the specified offsetremoveChild(nodename)Removes the specified node and returns itreplaceChild(newnode,oldnode)Replaces the oldnode with the newnode, and returns the oldnodereplaceData(offset,count,stringdata)Replaces the characters from the specified offset with the stringdataThe Document objectThe document object is the root element in the node-tree. All nodes in the node tree are child nodes of the document object.The document objects properties, methods, and events are described below:PropertiesPropertyDescriptionattributesReturns a NamedNodeMap that contains all attributes of a nodechildNodesReturns a node list that contains all children of a nodedoctypeReturns the DTD or Schema for the documentdocumentElementReturns the root element of the documentfirstChildReturns the first child node of a nodeimplementationReturns the DOMImplementation object for this particular documentlastChildReturns the last child node of a nodenextSiblingReturns the node immediately following a node. Two nodes are siblings if they have the same parent nodenodeNameReturns the name of the nodenodeTypeReturns the node type as a numbernodeValueReturns the value of the nodeownerDocumentReturns the Document object of a node (returns the root node of the document)parentNodeReturns the parent node of a nodepreviousSiblingReturns the node immediately preceding a node. Two nodes are siblings if they have the same parent nodeMethodsMethodDescriptionappendChild(tagname)Appends a new child node to a nodecloneNode(boolean)Creates an exact clone node of a node. If the boolean parameter is set to true, the cloned node clones all the child nodes of the original node as wellcreateAttribute(attrname)Creates an Attr node with the specified namecreateCDATASection(text)Creates a CDATASection node, containing the specified textcreateComment(text)Creates a comment node, containing the specified textcreateDocumentFragment()Creates an empty documentFragment objectcreateElement(tagname)Creates an element node with the specified namecreateEntityReference(refname)Creates an entityReference node with the specified namecreateProcessingInstruction(target,text)Creates a processingInstruction node, containing the specified target and textcreateTextNode(text)Creates a text node, containing the specified textgetElementsByTagName(tagname)Returns the specified node, and all its child nodes, as a node listhasChildNodes()Returns true if a node has child nodes. Otherwise it returns falseinsertBefore(newnode,refnode)Inserts a new node (newnode) before the existing node (refnode)removeChild(nodename)Removes the specified node and returns itreplaceChild(newnode,oldnode)Replaces the oldnode with the newnode, and returns the oldnodeThe Element objectThe element object represents the element nodes in the document. If the element node contains text, this text is represented in a text node.The element objects properties and methods are described below:PropertiesPropertyDescriptionattributesReturns a NamedNodeMap that contains all attributes of a nodechildNodesReturns a node list that contains all children of a nodefirstChildReturns the first child node of a nodelastChildReturns the last child node of a nodenextSiblingReturns the node immediately following a node. Two nodes are siblings if they have the same parent nodenodeNameReturns the name of the node (depending on the node type)nodeTypeReturns the node type as a numbernodeValueReturns the value of the nodeownerDocumentReturns the Document object of a node (returns the root node of the document)parentNodeReturns the parent node of a nodepreviousSiblingReturns the node immediately preceding a node. Two nodes are siblings if they have the same parent nodetagNameReturns the name of the element nodeMethodsMethodDescriptionappendChild(tagname)Appends a new child node to a nodecloneNode(boolean)Creates an exact clone node of a node. If the boolean parameter is set to true, the cloned node clones all the child nodes of the original node as wellgetAttribute(attrname)Returns the value of the specified attributegetAttributeNode(attrname)Returns the specified attribute node as an Attr objectgetElementsByTagName(tagname)Returns the specified node, and all its child nodes, as a node listhasChildNodes()Returns true if a node has child nodes. Otherwise it returns falseinsertBefore(newnode,refnode)Inserts a new node (newnode) before the existing node (refnode)normalize()Combines all subtree Text nodes into a single oneremoveAttribute(attrname)Removes the specified attributes valueremoveAttributeNode(attriname)Removes the specified attribute noderemoveChild(nodename)Removes the specified node and returns itreplaceChild(newnode,oldnode)Replaces the oldnode with the newnode, and returns the oldnodesetAttribute(attrname,attrvalue)Sets the value of the named attributesetAttributeNode(attrname)Inserts the specified new attribute to the elementThe Node ObjectThe node object represents a node in the node-tree.The node objects properties and methods are described below:PropertiesPropertyDescriptionattributesReturns a NamedNodeMap that contains all attributes of a nodechildNodesReturns a node list that contains all children of a nodefirstChildReturns the first child node of a nodelastChildReturns the last ch
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新质生产力:时代内涵与核心要义
- 大额人民币兑换课件
- 天津新区政策解读课件
- 2025年辅警招聘考试试题(必刷)附答案详解
- 广发银行清远市清新区2025秋招笔试创新题型专练及答案
- 七夕主题甜点之路
- 2025年反射疗法师大赛理论能力提升B卷题库【完整版】附答案详解
- 2025年医学研究方法学统计分析试题答案及解析
- 解析卷公务员考试《常识》专题攻克试卷(附答案详解)
- 广发银行杭州市余杭区2025秋招数据分析师笔试题及答案
- 2025年度反洗钱阶段考试培训试考试题库(含答案)
- 收割芦苇施工方案
- 普通黄金现货购买合同8篇
- 三力测试考试题库及答案视频讲解
- 2025年河南省人民法院聘用书记员考试试题及答案
- 2025年中学教师资格考试《综合素质》核心考点与解析
- 口腔冠延长术
- 部编版七年级语文上册《闻王昌龄左迁龙标遥有此寄》课件
- 诊所经营管理课件
- 2024年江苏省连云港市辅警协警笔试笔试模拟考试(含答案)
- 铁路工务介入管理办法
评论
0/150
提交评论