Display XML data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have an XML message returned to me in the VBA behind a form. I am putting
it in a MsgBox to be displayed to the user. But it comes out in XML, tags
and all. Is there a way I can display it without the tags so it is more
readable?
Thanks,
Steve
 
If the XML is relatively simple, you could write some VBA code to strip out
the tags ...

Public Sub ParseXML()

Const strcXML As String = "<?xml version='1.0' encoding='UTF-8'?>" & _
"<TestMessage>Hello World!</TestMessage>"

Dim strParsedMessage As String

'Get everything to the right of the first '>'. This removes
'the XML declaration (the first line) leaving us with just
''<TestMessage>Hello World!</TestMessage>"
strParsedMessage = Mid$(strcXML, InStr(1, strcXML, ">") + 1)
Debug.Print strParsedMessage

'Now get everything to the right of the first remaining '>'
'leaving us with just 'Hello World!</TestMessage>'
strParsedMessage = Mid$(strParsedMessage, InStr(1, strParsedMessage,
">") + 1)
Debug.Print strParsedMessage

'And finally, get everything to the left of the first '<'
strParsedMessage = Left$(strParsedMessage, InStr(1, strParsedMessage,
"<") - 1)
MsgBox strParsedMessage

End Sub

If it's much more complicated than that, you might need to use a tool
specifically designed for parsing XML. You can use Microsoft's MSXML DLL
from VBA code by setting a reference (Tools, References in the VBA editor)
to Microsoft XML, v6.0 (or whatever is the latest version on the target PC).
I've only used it once, and it was some time ago, so I won't attempt to
advise you on its use, but you can get more help in the XML newsgroup,
microsoft.public.xml, or via the web-based interface at ...

http://support.microsoft.com/newsgroups/newsReader.aspx?dg=microsoft.public.xml
 
Brendan,
Thanks, I will check the string I am parsing a little more closely, I do
believe it is always in the same format, so may parse it like in your
example. Otherwise, I'll look into the utility.
Thanks,
Steve
 
Back
Top