Using Visual Basic ® With The MSXML Parser Ken Spencer Vice President 32X Corporation
Cross-Platform Interop Application Data Comm Windows DNA 2000 Other Platforms Application Framework implementation Data Comm Core Standards Application Schemas FrameworksPlatform/Tools Solutions and Applications Platform/Tools Framework implementation
The Microsoft ® XML Engine Freely distributed Freely distributed msdn.microsoft.com/downloads/webtechn ology/xml/msxml.asp Fast parser Fast parser Great for creating and reading XML data Great for creating and reading XML data Files Streams
Instantiating From ASP From ASP Dim xmlDoc Dim sXML Set xmlDoc = CreateObject("microsoft.xmldom") From Visual Basic From Visual Basic Dim xDoc As MSXML.DOMDocument Set xDoc = New MSXML.DOMDocument
Loading XML Data Stream Data Stream Data sXML = txtXML xmlDoc.async = False xmlDoc.loadXML (sXML) File Data File DataxmlDoc.Load("f:\data\customer01.xml")
Asynchronous Loading Async Property Async Property Defaults to True Requires checking readyState property Returns 0 – 4 4 indicates load complete Setting Async Setting Async xmlDoc.async = False Sets to false, loading will be synchronous
Retrieving XML Data Extract the XML Extract the XML txtOutput = xmlDoc.xml txtOuput txtOuput Contains entire XML stream
Working With Nodes Understand NodeType property Understand NodeType property Node Type Example NODE_ELEMENT The Offspring The Offspring NODE_ATTRIBUTE The Offspring > The Offspring > NODE_TEXT The Offspring The Offspring NODE_PROCESSING_INSTRUCTI ON NODE_DOCUMENT_TYPE
Working With Nodes Retrieve elements by name Retrieve elements by name getElementsByTagName Walk through children Walk through children IXMLDOMNodeList Check out DisplayNode
Searching For Nodes Search for node by name Search for node by name Build nodelist Use NextMode method to walk list See cmdNextNode_Click
Extracting Attributes Use Attributes property Use Attributes property Returns list of attributes Returned in XMLDOMNamedNodeMap object For nodeTypes of: NODE_ELEMENT NODE_ENTITY NODE_NOTATION getNamedItem will return attribute text See cmdGetBookAttribute_Click
Creating XML Create an empty document Create an empty document xmlDoc.loadXML " " Loads the parser Document is empty Has one blank node (required) Use appendChild to add nodes Extract XML with XML property See cmdCreateNode_Click
Where Now? Tip of the iceberg Tip of the iceberg XML is moving everywhere XML is moving everywhere MSXML MSXML Works with XSL stylesheets and schmas Much more under the hood References References