Public Sub trvProyecto_Select()
Dim txtPaso As String
Dim Elemento As XmlElement
Dim Elementos As XmlElement[]
Dim Subel As XmlElement
Dim Subels As XmlElement[]
Dim Valores As New String[]
Dim i As Byte
'Estos en realidad se leen de CDATA del XML
Dim Campos As String[] = ["contenido", "notas", "sinopsis"]
'Estos deberían ser constantes de la aplicación
Dim intContenido As Integer = 0
Dim intNotas As Integer = 1
Dim intSinopsis As Integer = 2
Valores.Resize(Campos.Count)
txtPaso = trvProyecto.Item.Key
lblActual.Caption = trvProyecto.Item.Text
Elemento = xmlObjeto.Root
Elementos = Elemento.GetChildrenByNamespace("id")
For Each Elemento In Elementos
If Elemento.Value = txtPaso Then
For i = 0 To Campos.Max
Subels = Elemento.Parent.GetChildrenByNamespace(Campos[i],, 2)
If Subels.Count Then
Subel = Subels[0]
Valores[i] = Subel.Value
Endif
Next
Endif
Next
'Y aquí ya se hacen «cositas» con los datos leídos.
txtPral.RichText = Valores[intContenido]
End
' Gambas class file
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
Export
'' Encode in JSON format in a human readable way. Based on a Laurent tool
Static Public Function Encode2(vData As Variant) As String
Dim sInput As String
Dim sOutput As String
Dim iStream As Stream
Dim $sReadChar As String
Dim $iTab As Integer
Dim $bQuote, $bBracket As Boolean
sInput = JSON.Encode(vData)
iStream = Open String sInput For Read
While (Not Eof(iStream))
$sReadChar = Read #iStream, 1
If ($sReadChar = "{" And Not $bQuote) Then
$iTab += 1
$sReadChar &= "\n" & Space$($iTab * 2)
Else If ($sReadChar = "}" And Not $bQuote) Then
$iTab -= 1
$sReadChar = "\n" & Space$($iTab * 2) & $sReadChar
Else If ($sReadChar = "\"") Then
$bQuote = Not $bQuote
Else If ($sReadChar = "[") Then
$bBracket = True
Else If ($sReadChar = "]") Then
$bBracket = False
Else If ($sReadChar = ":" And Not $bQuote) Then
$sReadChar &= " "
Else If ($sReadChar = "," And Not $bQuote) Then
If (Not $bBracket) Then
$sReadChar &= "\n" & Space$($iTab * 2)
Else
$sReadChar &= " "
Endif
Endif
sOutput &= $sReadChar
Wend
Close iStream
' replace null with ""
sOutput = Replace(sOutput, " null", " \"\"")
Return sOutput
End