Autor Tema: Como puedo leer datos de un archivo XML en VB6?  (Leído 16654 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Jarmandaros

  • -*-Miembro Eterno-*-
  • The Communiter-
  • *****
  • Mensajes: 3873
  • -^- Despicable Member -^-
    • Jarmandaros Blog
Como puedo leer datos de un archivo XML en VB6?
« : abril 21, 2011, 07:13:04 pm »
a ver quien me hecha una manita XD

quiero leer datos de un archivo XML pero tiene que ser en VB6 no VB.net

el archivo XML al que tengo acceso es del tipo

Código: [Seleccionar]
<?xml version="1.0" encoding="utf-8"?>
<data>
  <record ID="1" LName="jarmandaros" FName="SVC"</record>
</data>

y tengo este codigo

Código: [Seleccionar]
Private Function GetNodeValue(ByVal start_at_node As IXMLDOMNode, ByVal node_name As String, Optional ByVal default_value As String = "") As String
Dim value_node As IXMLDOMNode

    Set value_node = start_at_node.selectSingleNode(".//" & node_name)
    If value_node Is Nothing Then
        GetNodeValue = default_value
    Else
        GetNodeValue = value_node.Text
    End If
End Function

Private Sub cargarxml()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode
Dim i As Integer
Dim j As Integer
 
On Error Resume Next
    ' Load the document.
    Set xml_document = New DOMDocument
    xml_document.Load m_AppPath & "prueba.xml"

    ' If the file doesn't exist, then
    ' xml_document.documentElement is Nothing.
    If xml_document.documentElement Is Nothing Then
        ' The file doesn't exist. Do nothing.
        Exit Sub
    End If

    ' Find the Values section.
    Set values_node = xml_document.selectSingleNode("data")
   
    ' Read the saved values.
   
For i = 0 To xml_document.documentElement.childNodes.length
   
    Set values_node = xml_document.documentElement.childNodes(i)
    t2.Text = GetNodeValue(values_node, "record", "???") Next i
End Sub


y con dicho codigo no consigo sacar el "ID" a menos que el XML fuera del tipo

Código: [Seleccionar]
<?xml version="1.0">
<data>
<record ID>1</record ID>
<record LName>jarmandaros</record LName>
<record FName>SVC</record FName>
</data>

pero lastimosamente no es el caso  :cry:

ojala haya alguien que me pueda iluminar un poco, gracias de antemano  :thumbsup:
Queres Vender o Comprar un producto X? unite al grupo del Tiangue! en Facebook, solo necesitas una cuenta en FB. EL Tiangue!
Visita mi Blog

Desconectado Lucho

  • Sv Member
  • ***
  • Mensajes: 145
Re: Como puedo leer datos de un archivo XML en VB6?
« Respuesta #1 : abril 21, 2011, 08:02:45 pm »
si probas asi a ver si funciona

Private Function GetNodeValue(ByVal start_at_node As IXMLDOMNode, ByVal node_name As String, Optional ByVal default_value As String = "") As String
Dim value_node As IXMLDOMNode
Dim id As String

Set value_node = start_at_node.selectSingleNode(".//" & node_name)
    id = value_node.Attributes.getNamedItem("ID").text
   
    If value_node Is Nothing Then
        GetNodeValue = default_value
    Else
        GetNodeValue =  id
    End If
End Function
« Última Modificación: abril 21, 2011, 08:08:52 pm por Lucho »

Desconectado Jarmandaros

  • -*-Miembro Eterno-*-
  • The Communiter-
  • *****
  • Mensajes: 3873
  • -^- Despicable Member -^-
    • Jarmandaros Blog
Re: Como puedo leer datos de un archivo XML en VB6?
« Respuesta #2 : abril 21, 2011, 09:14:28 pm »
si probas asi a ver si funciona

Private Function GetNodeValue(ByVal start_at_node As IXMLDOMNode, ByVal node_name As String, Optional ByVal default_value As String = "") As String
Dim value_node As IXMLDOMNode
Dim id As String

Set value_node = start_at_node.selectSingleNode(".//" & node_name)
    id = value_node.Attributes.getNamedItem("ID").text
   
    If value_node Is Nothing Then
        GetNodeValue = default_value
    Else
        GetNodeValue =  id
    End If
End Function

Excelente, esa es la solucion  :yahoo:

Gracias Lucho  :thumbsup:
Queres Vender o Comprar un producto X? unite al grupo del Tiangue! en Facebook, solo necesitas una cuenta en FB. EL Tiangue!
Visita mi Blog