XMLDOM大全1Dom Objects introduce.docx
- 文档编号:27449889
- 上传时间:2023-07-01
- 格式:DOCX
- 页数:15
- 大小:21.02KB
XMLDOM大全1Dom Objects introduce.docx
《XMLDOM大全1Dom Objects introduce.docx》由会员分享,可在线阅读,更多相关《XMLDOM大全1Dom Objects introduce.docx(15页珍藏版)》请在冰豆网上搜索。
XMLDOM大全1DomObjectsintroduce
MicrosoftDOMObjectsTableofContents
Overview
DOMobjects
1.DOMDocument
2.XMLDOMElement
3.XMLDOMNode
4.XMLDOMNodeList
5.XMLDOMNamedNodeMap
6.XMLDOMCDATASection
7.XMLDOMAttribute
8.XMLDOMDocumentType
9.XMLDOMEntity
10.XMLDOMProcessingInstruction
11.XMLDOMParseError
XMLHTTPRequest
DOMobjectproperties(pleaseseeanotherDocument)
1.async
2.Attributes
3.childNodes
4.data
5.docType
6.documentElement
7.length
8.namespaceURI
9.nodeName
10.nodeType
11.The12Nodetypes
12.nodeTypedValue
13.nodeTypeString
14.nodeValue
15.ondataavailable
16.ownerDocument
17.parentNode
18.parsed
19.parseError
20.prefix
21.preserveWhiteSpace
22.resolveExternals
23.tagName
24.text
25.url
26.validateOnParse
27.value
DOMobjectmethods(pleaseseeanotherDocument)
1.abort()
2.appendChild()
3.cloneNode()
4.createAttribute(),createCDATASection(),createComment(),createElement(),createEntityReference(),createProcessingInstruction(),createTextNode()
5.createNode()
6.getAttribute()
7.getAttributeNode()
8.getElementsByTagName()
9.getNamedItem()
10.hasChildNodes()
11.insertBefore()
12.load()
13.loadXML()
14.nextNode()
15.nodeFromID()
16.removeAttribute()
17.removeAttributeNode()
18.removeChild()
19.removeNamedItem()
20.replaceChild()
21.reset()
22.save()
23.selectNodes()
24.selectSingleNode()
25.send()
26.setAttribute()
27.setAttributeNode()
28.setNamedItem()
29.transformNode()
30.transformNodeToObject()
MicrosoftDOMDocumentObjectTutorial
XMLProgrammingwithVBandASPgivesaVB/ASPdeveloperafrom-the-ground-upstarttoXMLandXMLprogramminginVBandASP.Funtoreadandeasygoing,thisisano-frillsbookwhichgetsrighttothepoint.MoreadvancedtopicsincludeBizTalk,schemas,webclassesandXSL.
Whatthischapterofthebookcovers:
✶DescriptionsoftheMicrosoftXMLobjects
✶Samplecodeformostofthemethodsandproperties
✶Easy-referencetableguidetotheobjects
Overview
MicrosofthasshippedsomeveryusefulobjectswithIE5thatcanbeusedfromanyprogramminglanguagethatcanmakeuseofCOMobjects.Inthispartofthebook,wewillfocusontheXMLDOMobjectsusingVBorVBScript.
TobetterunderstandcodeordescriptionsoftheDOMDocument,trytothinkofanXMLdocumentasatree.Anotherusefulanalogyistothinkofparentsandtheirchildren.
TobetterunderstandcodeordescriptionsabouttheDOM,trytothinkofanXMLdocumentasatree.Anotherusefulanalogyistothinkofparentsandtheirchildren.Westartwiththeactualrootofthedocument,thenitmeandersdowntoeachprocessinginstruction,thedocumentrootelement,attributes,etc.TheseobjectsintheDOMareknownbythereowntype(e.g.,Element,Attribute,etc.),buteachtypeisgenerallycalledaNode.TheDOMgivesuscollectionsobjectsaswell,knownasNodeListswhenaparenthasmanychildrenthatneedtobegrouped.Figure describeshowthetreestructureisimplemented:
Thischapter,whilecomprehensive,shouldnotbeusedasacompletereference.
TheXMLDOMObjectimplementstheXMLDOMinterfaces.TheseinterfacesmakereusabilitythroughouttheDOMpractical.Becausethesetwoobjectssharethesameinterfaces,thecodebecomeseasiertounderstandandworkwith,whichwewillseeinashortwhile.
DOMobjects
Firstweneedtoexplainthevarious,commonDOMobjectsthatyouwillusewiththeMSXMLDOMObject.
WewillfocusontheexamplesoftheseXMLDOMobjectsshownintable .
0.0.1XMLDOMObjects
Objectname
Description
DOMDocument
ThisobjectrepresentstherootoftheXMLfile.
XMLDOMElement
ThisobjectrepresentseachelementintheDOM-Document,namelytheroot,rootelement,andeachotherelement.
XMLDOMNode
ThisobjectrepresentsasingleNodeinthedocumenttreeandincludessupportfordatatypes,namespaces,DTDs,andXMLSchemas.
XMLDOMNodeList
Usethisobjecttoaccess(byname)anditeratethroughtheXMLDOMNodecollection.
XMLDOMNamedNodeMap
Usethisobjecttoaccessanditeratethroughtheattributesinanelement.
XMLDOMCDATASection
ThisobjectrepresentsasectioninthevalueofanelementthatisclosedintheCDATAsectionbrackets,whicharecharactersthatcannotbeparsedbytheXML.
XMLDOMAttribute
ThisobjectrepresentsasingleattributeNodeforagivenelement.
XMLDOMDocumentType
ThisobjectrepresentstheDocumentType(DTD)inanXMLfile.
XMLDOMEntity
ThisobjectrepresentsanentityintheDTDsectionoftheXMLfile.
XMLDOMProcessingInstruction
ThisobjectrepresentsaprocessinginstructionfoundintheXMLfile.
XMLDOMParseError
Thisobjectreturnsdetailedinformationaboutthelasterror,includingthelinenumber,characterposition,andatextdescription.
XMLHTTPRequest
Thisobjectenablesyoutoestablishaconnectiontoawebserverfromyourcodeandsendput,get,andotherstandardHTMLrequests.
Inourexamples,wewillrefertotheseobjectsusingthenameslistedintable .
0.0.1XMLobjectnamingconventions(continued)
XMLobjectinterface
Ournamingconvention
DOMDocument
objDOMDocument
XMLDOMNode
objXMLDOMNode
XMLDOMNodeList
objXMLDOMNodeList
XMLDOMNodeListMap
objXMLDOMNodeListMap
XMLDOMParseError
objXMLDOMParseError
XMLDOMElement
objXMLDOMElement
XMLDOMAttribute
objXMLDOMAttribute
ThismanuscriptisanabridgedversionofachapterfromtheManningPublicationsbookXMLProgrammingwithVBandASP.ThischapterlooksattheMicrosoftDOMobjects.NOTE:
Mostimageshavebeenremovedtoincreasespeedandmanyofthecodecommentshavealsobeenremovedforpresentation.Pleasepurchasethebooktoenjoythefullexperienceofallthechapterswithimagesandcodecomments!
DOMDocument
TheDOMDocumentobjectrepresentstherootoftheXMLfile.AsthefileisloadedintotheDOMDocument,theXMLfileanditsexternalreferences,suchasDTDs,getvalidatedbytheDOMDocument.
TheDOMDocumentisthefirstportofcalltotheXMLfile.Thisistheonlyobjectthatcanbecreated.Alltheotherobjects,liketheelements,canonlybecreatedoraccessedfromtheDOMDocumentobject.
Example
ThisexampleloadsanXMLfileintoaDOMDocumentobject:
DimobjDOMDocumentAsDOMDocument
SetobjDOMDocument=NewDOMDocument
objDOMDocument.async=False
objDOMDocument.Loadhttp:
//localhost/xmlcode/people2.dtd
XMLDOMElement
ThisobjectrepresentseachelementintheXMLtree.TheXMLDOMElementincludessupportformanipulatingtheelementandtheattributesassociatedwiththeelement.
TheattributesassociatedwithanelementareaddedandmanipulatedviatheXMLDOMElementobject.
Example
ThefollowingexamplereturnstherootelementoftheXMLfilefromaDOMDocument:
DimobjDOMDocumentAsDOMDocument
DimobjXMLDOMElementAsIXMLDOMElement
SetobjDOMDocument=NewDOMDocument
objDOMDocument.async=False
objDOMDocument.Load"http:
//localhost/xmlcode/people2.dtd"
SetobjXMLDOMElement=objDOMDocument.documentElement
XMLDOMNode
ThisisoneofthebaseobjectsoftheDOM.MostoftheotherDOMobjectsinheritthisobject;therefore,youwillseealotofpropertiesandmethodsrepeatedineachoftheseobjects.
Theseobjectsare:
✶DOMDocument
✶XMLDOMAttribute
✶XMLDOMCDATASection
✶XMLDOMComment
✶XMLDOMDocumentFragment
✶XMLDOMDocumentType
✶XMLDOMElement
✶XMLDOMEntity
✶XMLDOMEntityReference
✶XMLDOMNotation
✶XMLDOMProcessingInstruction
✶XMLDOMText
✶XTLRuntime
AlthoughalltheseobjectsinheritmethodsandpropertiesfromtheXMLDOMNodeobject,theywillallalsohavepropertiesandmethodsthatareuniquetotheirfunction.Forexample,theXMLDOMElementobjecthasextramethodsforobtainingattributeinformation.TheXMLDOMNodeinterfaceprovidesjustthebasicinformation,likethenameoftheNode,itstext,etc.
ToknowwhichtypeofNodeiscurrentlybeingaccessed,thenodeTypepropertyreturnswhichtypeofNodeyouarereferencingwhenusingtheXMLDOMNodeobject,whichisexplainedindetaillaterinthischapterunderthenodeTypeproperty.
Also,seethedocTypepropertyformoreinformationonDualinterfaces.Thisexplainshowtocastfromonetypeofobjecttotheother.
Example
ThefollowingexampleisthesameastheexamplefromtheXMLDOMElement,exceptitnowusestheXMLDOMNodeobjecttoreturntherootelementoftheXMLfilefromaDOMDocument.
DimobjDOMDocumentAsDOMDocument
DimobjXMLDOMNodeAsIXMLDOMNode
SetobjDOMDocument=NewDOMDocument
objDOMDocument.async=False
objDOMDocument.Load"http:
//localhost/xmlcode/people2.dtd"
SetobjXMLDOMNode=objDOMDocument.documentElement
XMLDOMNodeList
TheXMLDOMNodeListobjectisacollectionofNodes.ItsmethodsallowustoiteratethroughallthechildrenNodesofaNode.YoucanusetheForEach...Nextloopforthisiteration.However,youcanalsochoosetoiteratethroughtheseNodesusingitsmethodofnextNode().
Thisobjectisreturnedintheproperty,suchaschildNodes,ormethodssuchasgetElementsByTagName()andselectNodes().
Example
ThefollowingexampleusesthechildNodespropertyoftheDOMDocumenttoreturnthechildrenNodesoftherootelementoftheDOMDocument.(FormoredetailsseethechildNodesproperty,whichalsoshowsanexampleofhowtoiteratethroughtheXMLDOMNodeListcollection.)
DimobjDOMDocumentAsDOMDocument
DimobjXMLDOMNodeListAsIXMLDOMNodeList
SetobjDOMDocument=NewDOMDocument
objDOMDocument.async=False
objDOMDocument.Load"http:
//localhost/xmlcode/people2.dtd"
SetobjXMLDOMNodeList=objDOMDocument.documentElement.childNodes
XMLDOMNamedNodeMap
ThisistheothercollectionobjectintheDOM.Itisusedtoiteratethroughtheattributesforaspecificelement.Italsoallowsyoutomanipulatetheattributecollectionforanelement.Tonameaf
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- XMLDOM大全1Dom Objects introduce XMLDOM 大全 Dom
![提示](https://static.bdocx.com/images/bang_tan.gif)