Anthony wrote:
<snip>
> I have this piece of XML:
>
> <result>success</result>
> <message_count>2</message_count>
> <messages>
> * *<message>
> * * * * <sender_name>Joe Parnell</sender_name>
> * * * * <sender_email>some...@example.com</sender_email>
> * * * * <subject><![CDATA[Beta Test - Anthony]]></subject>
> * * * * <video_link>http://example.com/videos/33.3gp</video_link>
> </message>
>
> <messages>
> * *<message>
> * * * * <sender_name>Joe Parnell</sender_name>
> * * * * <sender_email>some...@example.com</sender_email>
> * * * * <subject><![CDATA[Beta Test #2 - Anthony]]></subject>
> * * * * <video_link>http://example.com/videos/34.3gp</video_link>
> </message>
>
> </messages>
> </response>
There are at least two errors in the xml above that will prevent it
from being parsed:
a) there's a missing <response> node that seems to be closed at the
end of the xml (<response>....</response>)
b) you open the node <messages> twice, but you only close it once.
> So obvious this is the return of multiple 'message' nodes and that's
> what's throwing me. How do I process these? I need to be able to parse
> out each individual message. I am totally lost. Can anyone help?
<snip>
My guess is that if you correct the errors above you can feed the xml
to a XmlDocument and then read each node back:
<example
Dim Doc As New Xml.XmlDocument
Doc.LoadXml(Source) '<-- your xml text here
Dim Response As Xml.XmlNode = Doc.DocumentElement
Debug.Print("Result: {0}", _
GetNodeText(Response, "result"))
Debug.Print("Message count: {0}", _
GetNodeText(Response, "message_count"))
For Each Node As Xml.XmlNode _
In Response.SelectNodes("messages/message")
Debug.Print("Message:")
Debug.Print(" sender_name: {0}", _
GetNodeText(Node, "sender_name"))
'...
'I guess you know how to go from here
'...
Debug.Print("")
Next
'--------------------------------------------------------
Function GetNodeText( _
ByVal Parent As Xml.XmlNode, _
ByVal Path As String _
) As String
'--------------------------------------------------------
Dim N As Xml.XmlNode = Parent.SelectSingleNode(Path)
If N IsNot Nothing AndAlso N.FirstChild IsNot Nothing Then
Return N.FirstChild.Value
End If
Return ""
End Function
</example>
HTH.
Regards,
Branco.
|