Converts a JSON string to an XML representation.
A JSON string to convert to XML.
Converts a JSON string to an XML representation.
Visual Basic |
---|
Public Function JSONtoXML( _ ByVal JSON As String _ ) As String |
A JSON string to convert to XML.
An XML markup of the JSON string.
All Chromium DevTools Inspector Protocol methods require JSON for input and return JSON for output.
Unless you have a JSON parser you can use an XML parser as an alternative by converting the JSON output to XML and processing it with MSXML COM library and XPath queries.
This example demonstrates how to handle OnDevToolsWebSocket event for CSS.styleSheetAdded Inspector Protocol Event and convert the JSON data to XML data.
Private Sub WebKitX_OnDevToolsWebSocket(ByVal Data As String) On Error Resume Next If InStr(Data, "CSS.styleSheetAdded") > 0 Then Dim xDOM As Object Set xDOM = XML_DOM(JSONtoXML(Data)) StyleSheets.Add xDOM.selectSingleNode("//styleSheetId").Text, xDOM.selectSingleNode("//sourceURL").Text End If Err.Clear End Sub Public Function XML_DOM(Optional sAnyXML) As IXMLDOMDocument Dim xDOM As DOMDocument30 Set xDOM = New DOMDocument30 xDOM.Async = False xDOM.resolveExternals = False xDOM.validateOnParse = False If Not IsMissing(sAnyXML) Then If IsObject(sAnyXML) Then xDOM.Load sAnyXML ElseIf sAnyXML <> vbNullString Then If InStrB(sAnyXML, "<") Then xDOM.loadXML sAnyXML Else xDOM.Load sAnyXML End If End If End If xDOM.SetProperty "SelectionLanguage", "XPath" xDOM.SetProperty "SelectionNamespaces", vbNullString Set XML_DOM = xDOM End Function