Created
January 23, 2014 22:15
-
-
Save gepser/8587933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Recibir un XML como un String | |
Private Function LoopXML(ByVal xml As String) As String | |
Try | |
Dim strSalida As String = "" | |
Dim nt As NameTable = New NameTable() | |
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(nt) | |
nsmgr.AddNamespace(String.Empty, "") | |
Dim context As XmlParserContext = New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None) | |
Dim reader As XmlTextReader = New XmlTextReader(xml, XmlNodeType.Element, context) | |
'Hasta que termine de leer | |
Do While (reader.Read()) | |
'Para recorrer los nodos de todo tipo | |
Select Case reader.NodeType | |
'Si encontramos un nodo, ejemplo: "<nodo_test>" | |
Case XmlNodeType.Element | |
'Si el nodo tiene atributos los recorremos | |
If reader.HasAttributes Then | |
While reader.MoveToNextAttribute() | |
End While | |
End If | |
'Verificamos que exista un nodo con un nombre en particular | |
If reader.Name.ToUpper = "NODO_TEST" Then | |
strSalida += reader.Name | |
End If | |
'Obtenemos el valor del nodo, en este caso: "<nodo_test>1237456</nodo_test>" obtendríamos "1237456" | |
Case XmlNodeType.Text | |
strSalida += " = " & reader.Value & vbCrLf | |
Case XmlNodeType.EndElement | |
End Select | |
Loop | |
Return strSalida | |
Catch ex As Exception | |
Return ex.Message | |
End Try | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment