Purpose
The XML keyword class allows for the manipulation, parsing, and output of XML tree structures.
The tree structure is manipulated in memory for performance and can be output in text form or parsed from existing XML text.
Example
' Sample Web Service from:
' This is a simple example of making a Web Services request to an external provider, in this
' case to get the dictionary definition of a word.
' Define our HTTP and XML objects to be used
Dim WebService as HTTP
Dim XMLObj as XML
Dim Count as Integer
' Set the SOAP query obtained from the Web Service provider. Double quotes have been modified to
' single quotes for readability
XMLObj.Text = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><Define xmlns='http://services.aonaware.com/webservices/'><word>string</word></Define></soap:Body></soap:Envelope>"
' Move to the root node
XMLObj.RootNode
' Find a node with the input parameter we wish to specify
XMLObj.FindFirst("word",fcRecursive)
' Assign our value to the input parameter
XMLObj.Value = "program"
' Set the body of the request to the text form of our XML object
WebService.SendBody = XMLObj.Text
' Specify that the content is xml
WebService.SendContentType = "text/xml"
' Set the SOAP header
WebService.SendHeader("SOAPAction",Chr(34) & "http://services.aonaware.com/webservices/Define" & Chr(34) )
' Post the request to the provider
WebService.Post("http://services.aonaware.com/DictService/DictService.asmx")
' Reuse our XML object to parse the reply
XMLObj.Text = WebService.ReplyAttachment(0)
' Start at the top
XMLObj.RootNode
' Find the output parameter we want to use
XMLObj.FindFirst("WordDefinition", fcRecursive)
' Move to the first child ( the text value )
XMLObj.ChildNode
' Output the result
Debug "Definition:"
Debug XMLObj.Value
' Display data about the returned XML
Debug "XML Details:"
Debug "Encoding: " & XMLObj.Encoding
If XMLObj.Compression Then
Debug "Compression: ON"
Else
Debug "Compression: OFF"
End If
Debug "Charset: " & XMLObj.Charset
Debug "Namespace: " & XMLObj.NameSpace
Debug "Version: " & XMLObj.Version
Debug "XML Nodes in a Definition (forwards):"
XMLObj.RootNode
XMLObj.FindFirst("Definition",fcRecursive)
XMLObj.MoveFirst
Do While XmlObj.IsValidNode
Debug XmlObj.Name
XMLObj.MoveNext
Loop
Debug "XML Nodes in a Definition (backwards):"
XMLObj.RootNode
XMLObj.FindFirst("Definition",fcRecursive)
XMLObj.MoveLast
Do While XmlObj.IsValidNode
Debug XmlObj.Name
XMLObj.MovePrev
Loop
XMLObj.RootNode
XMLObj.FindFirst("Definition",fcRecursive)
Do While XMLObj.IsValidNode
Count = Count + 1
XMLObj.FindNext
Loop
Debug "There are " & count & " Definitions"
XMLObj.RootNode
XMLObj.FindFirst("Dictionary",fcRecursive)
XMLObj.FindLast
Debug "The last Dictionary node has " & XMLObj.NumChildren & " children"
XMLObj.FindPrev
If XMLObj.ChildExists("Name") Then
Debug "The second to last one has a Name node"
Else
Debug "The second to last one has no Name node"
End If
XMLObj.ParentNode
Debug "Its parent node is " & XMLObj.Name
XMLObj.RootNode
XMLObj.FindFirst("Definition",fcRecursive)
Debug "The Word node contains " & XMLObj.Child("Word")
XMLObj.RootNode
XMLObj.FindFirst("DefineResponse",fcRecursive)
Debug "DefineResponse has a namespace " & XMLObj.Namespace
XMLObj.CreateChild("Language","English")
XMLObj.Attribute("DefAttr") = "LangSpec"
Debug "After adding a Language child:" & XMLObj.Text
XMLObj.Text = "<Outer>" & fcLF & "<Inner>" & fcLF & "</Inner>" & fcLF & "</Outer>" & fcLF
XMLObj.RootNode
XMLObj.FindFirst("Inner",fcRecursive)
Debug "Found Inner on line " & XMLObj.LineNumber
|