Gambas-it

Gambas3 => Segnalazione bug => Topic aperto da: md9327 - 13 Giugno 2012, 22:15:15

Titolo: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 13 Giugno 2012, 22:15:15
per vuott, ambassador gambas...  ;D

Ho riscontrato un'altro problema, legato alla libreria gb.xml, in particolare con XMLWriter (ma probabilemnte c'è qualcosa anche con XMLReader).

Faccio un esempio che forse rende meglio l'idea. Io devo scrivere un file xml, con una serie di tag nidificati, dove la maggior parte degli elementi hanno un un'uico valore (Text), come ad esempio:
Codice: [Seleziona]
<Tags>
<Tag1>valore</Tag1>
<Tag2>valore</Tag2>
</Tags>
Come si può notare, Tag1 e Tag2 hanno un valore, e questo viene racchiuso tra l'apertura del tag "<Tag1>", e la sua chiusura "/Tag1>".
Fino a qui la logica credo sia semplice e chiara, e questa è stata finora adottata in tutte le mie applicazioni, compreso pgDesigner (che di file xml ne legge parecchi).

Dovo aver scaricato l'ultima versione di Gambas3 in formato sorgente, oggi è la 4827, ho riscontrato che la lettura ha qualcosa che non và (ancora da chiarire), mentre la scrittura ha un errore, che ho verificato nei sorgenti della classe XmlWriter.class, di cui posto la parte interessata al problema:
Codice: [Seleziona]
Public Sub StartElement(TagName As String, Optional Attributes As String[], Optional Prefix As String, Optional URI As String)
  
  Dim Xmlns, s, sData As String
  Dim i As Integer = 0
  If URI Then
    Xmlns = " xmlns"
    If Prefix Then Xmlns &= ":" & Prefix
    Xmlns &= "=\"" & URI & "\""
  Endif
  If Prefix Then TagName = Prefix & ":" & TagName
  
  sData = "<" & TagName
  
  If Attributes
    If (Attributes.Count Mod 2) Then Attributes.Push("")
    For i = 0 To Attributes.Max Step 2
      sData &= " " & Attributes[i] & "=\"" & Attributes[i + 1] & "\""
    Next
  Endif
  
  sData &= Xmlns
  
  If Not $TagEnded Then 'On ferme le tag précédent
    Write(">" & If($indent, "\n", ""), True)
  Endif
  
  $TagEnded = False
  
  Write(sData)
  
  PileElements.Push(TagName)
  
End

Public Sub EndElement()
  
  Dim tag As String
  
  If Not PileElements.Count Then Return
  
  tag = PileElements.Pop()
  
  If Not $TagEnded Then 'On ferme le tag précédent
    Write(" />" & If($indent, "\n", ""), True) 'Pas de contenu
    $TagEnded = True
  Else
    Write("</" & tag & ">")
  Endif
  
End
il codice applica una logica errata, o perlomeno parte da un presupposto non completamente corretto. In pratica il tag viene aperto e chiuso tramite lo stato della variabile $TagEnded, non tenendo conto che potrebbe esserci un valore Text in mezzo. Questo causa la scrittura errata del tag, come da esempio:
Codice: [Seleziona]
<Tag1valore />
<Tag2valore />
in pratica unisce il nome del tag con il valore stesso.
La sequenza con cui viene aperto e chiuso il tag, e associato a questo un valore è come da esempio:
Codice: [Seleziona]
DIM oXml As XmlWriter
...
oXml.StartElement("Tag1")
oXml.Text("valore")
oXml.EndElement()

Con la versione 3.1.1 la cosa funzionava, ma ora con gli ultimi aggiornamenti non và più. Non sò se dalla 3.1.1, le build successive riportano tutte lo stesso problema, ma di sicuro la 4827.

Caro vuott, dato che scrivere direttamente a Benoit mi è sempre restato piuttosto difficoltoso, sarebbe di gran utilità (e non solo per me), notificare a Minisini questo problema, per poter correggere al più presto.
Tieni conto che il pezzo di sorgente ad inizio post è estratto dalla classe inclusa nei sorgenti di gambas, ed è scritta nello stesso linguaggio, per cui è semplice sistemarla.

Grazie
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 14 Giugno 2012, 01:02:13
per vuott, ambassador gambas...  ;D
.................

Le comunichiamo che gli Uffici di questa Ambasciata hanno provveduto a trasmettere formalmente al Presidente Minisini quanto da Lei sopra rappresentato.
L'Ambasciata si adopererà senza indugio alcuno, non appena sarà giunta eventuale risposta, a trascrivere su questa pagina il contenuto della medesima.   ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 14 Giugno 2012, 10:15:50
Più che ambasciatore, sei una perfetta segretaria...  ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 14 Giugno 2012, 11:16:02
Più che ambasciatore, sei una perfetta segretaria...  ;D

...già ! :-X Non me ne ero accorto.

...ed allora, sotto potete vedere una foto di Vuott trasformato, come d'incanto e limitatamente per questa occasione, da Ambasciatore in una segretaria sexy.  
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 14 Giugno 2012, 14:15:21
A parte che sà di "fregatura"...  ;D

Anche così, come ambasciatRICE non saresti male...  ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 14 Giugno 2012, 21:27:36
Anche così, come ambasciatRICE non saresti male...  ;D

...del resto si dice anche: "Ambasciator non porta pen... A".  :P
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 14 Giugno 2012, 22:59:59
...in effetti...  ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 15 Giugno 2012, 01:49:07
Allora... ho ricevuto una prima risposta da un utente della Lista, il quale pare dica che è stato già affrontato questo problema, e che dovrebbe essere stato risolto:

"This should be solved in the revision #4826."


...però mi pare che tu lo abbia riscontrato anche con la rev. 4827. Se non erro.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 15 Giugno 2012, 10:09:42
Esatto!  :D

Tra l'altro ieri ho scaricato la 4829, ma dà errore all'apertura dell'ide. Sono ritornato alla 4827...

Risolto non credo proprio, in quanto già nei sorgenti ci sono evidenti anomalie.

Ora stò provando ad usate XmlDocument, invece del XmlReader/XmlWriter, e mi pare funzioni anche se ha una logica completamente diversa, ma più vicina ad altre libreria di altri linguaggi.

Stò pensando che, probabilmente, l'idea dello sviluppatore è quella di eliminare le due classi XmlReader/Writer, in favore di ulteriori classi più dinamiche...
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 15 Giugno 2012, 10:22:37
Stamane, in effetti, trovo una correzione da parte di quell'utente, il quale così mi scrive:
"Oops, this is the #4829, not the #4826, of course..."

...però la 4829 non funziona proprio. Bisognerà attendere una successiva versione per il superamento di questo errore).
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 15 Giugno 2012, 10:25:25
...però la 4829 non funziona proprio. Bisognerà attendere una successiva versione per il superamento di questo errore).

Leggo ora un messaggio di Minisini:

"The bug in toolbar management that made the IDE crashing at startup with
the "Invalid object" error should have been fixed.

In revision #4830.

Please confirm!

--
Benoît Minisini
"
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 15 Giugno 2012, 11:43:02
Lo vedo stasera... e ti faccio sapere...
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 15 Giugno 2012, 12:33:58
Ho inviato i tuoi dubbi aggiunti nel tuo penultimo messaggio; ed il tipo che aveva risposto lì nella Lista internazionale su questo argomento, da te sollevato, aggiunge quanto segue (te lo riporto nella lingua originaria per evitare errori di interpretazione e traduzione da parte mia):

" Anomalies ? Where ?


The idea is not to "eliminate" XmlReader and XmlWriter. For two reasons :

- They still can be very useful. The new XmlReader and XmlWriter are not
made for little documents (as said, the others are more dynamic), but they
are made for streams.
For example, you can "connect" a TCP socket to XmlReader and Writer, and
they will read/write the XML for you. Here is a little example with
XmlReader (the page is in french, but the program is in english) :
http://www.gambasforge.org/code-63-xmltalk.html.

- For compatibility reasons. Before the new gb.xml arrived, the
XmlDocument/XmlNode classes were very poor (unusable). So, everyone use
XmlReader and XmlWriter...

Regards,
Adrien.
"
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 15 Giugno 2012, 13:35:37
Il mio era infatti solo un dubbio, se non è così, meglio...

Riguardo alla gestione di piccoli documenti... ma che vuol dire? O sono grandi, oppure non li tratta?
Dalle prove che ho fatto, sono stati effettuati un mucchio di cambiamenti, che hanno reso inagibile tutto il codice utilizzato.
Tanto per farla semplice, già dopo un Open(file), oppure un OpenStream(), sembra che leggano, eppure non fanno alcun parsing del contenuto xml, restituendo 0 in tutte le proprietà. Questo ovviamente rende un pochino difficile la decodifica dei dati... non credi?

Sempre nelle prove, ho provato ad usare XmlDocument, XmlElement e XmlNode, e devo dire che in qualche, anche perchè cambia la logica, i dati riesco ad ottenerli, anche se ho trovato anche qui qualche anomali, del tipo che nel Save(), ai test vengono aggiunti spazi indesiderati in testa e in coda.
E' pur vero che, come da risposta, queste classi sono ancora incomplete, e quindi ancora non stabile, quindi meglio non utilizzarle.

Ad ogni modo, i file xml che tratto, possono essere grandi o piccoli, a seconda delle esigenze, ma questo non può essere causa di malfunzionamenti. Al contrario, mi aspetto che i malfunzionamenti si verifichino appunto con file di grosse dimensioni, in quanto è probabile che la libreria usi il sistema DOM, caricando tutto in memoria.
Oltre a questo, i file che tratto possono avere strutture semplici e complesse, con tag con attributi, testi, o sottoelementi, in maniera gerarchica e a vari livelli. E' ovvio che, ove possibile, ho cercato di ottimizzare e semplificare le logiche, ma non posso farlo per tutto, altrimenti l'uso del protocollo xml perde di significato. E' anche ovvio che non stò usando modalità ipercomplesse, come di solito mi trovo a trattare anche per lavoro, per cui non vedo grosse difficoltà.

Stasera posto qualche esempio di lettura/scrittura, codice che è inserito nei miei programmi, così magari possono dargli un'occhiata, e verificare quanto dico...  :-\

P.S.: forse sarebbe il caso che negli esempi, inserissero qualcosa a riguardo, così magari si risolvono le lacune della documentazione, ed evitare di andare per tentativi...
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 15 Giugno 2012, 17:50:22
Ho scaricato l'ultima versione dei sorgenti di Gambas3 (4833), ma le anomalie persistono.

Il seguente è il codice che stò utilizzando, e che è un estratto depurato di quello originale usato in pgDesigner3, per la lettura del file di configurazione, che prima funzionava e ora non và più:
Codice: [Seleziona]
Public Sub Main()
  Dim reader As New XmlReader
  Dim s As String[]
 
  reader.Open("/home/luigi/tmp/text.xml")
  While (Not reader.Eof)
    s = [reader.Node.Depth,
         reader.Node.Name,
         reader.Node.Type,
         reader.Node.Value,
         reader.Node.Attributes.Count]
    Print "[" & s.Join("],[") & "]"
    Print reader.Node.Dep

    Select Case reader.Node.Type
      Case XmlReaderNodeType.Element
        Print "Element::" & reader.Node.Name, reader.Node.Value
        For Each reader.Node.Attributes
          Print reader.Node.Name, reader.Node.Value
        Next
      Case XmlReaderNodeType.EndElement
        Print "EndElement::"
      Case XmlReaderNodeType.Text
        Print "Text::" & reader.Node.Value
    End Select
    Print "Read = " & reader.Read() 'return EndStream
  Wend
End
ci sono alcuni Print, per capire cosa contengono le variabili, ma sono tutte vuote. I problemi non cambiano, sia con Open() che con fromString().
Ho anche usato il file di prova contenuto nei sorgenti di gambas "text.xml", il cui contenuto è molto semplice:
Codice: [Seleziona]
<?xml version="1.0"?>
<toto machin="toto">Hello<truc>Bouh</truc><!-- Hello -->
</toto>
<titi>Hellow</titi>

In allegato invio anche quello usato per la versione di pgDesigner3 che stò sviluppando, e che è un tantino più grande e più articolato.

Stò cercando di localizzare il problema nei sorgenti di gambas3 ma non riesco a trovare il bandolo della matassa, in quanto parte è in linguaggio gambas, parte è in C, parte è di libreria esterna...
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: vuott - 16 Giugno 2012, 01:09:53
Oramai sono una pallina di ping-pong  :rolleyes: (è dura la vita dell'Ambasciatore !) e ti riporto un altro messaggio del nostro amico lì nella lista internazionale. Lui dice di aver letto questa discussione e di aver risposto. Ma qui non vedo niente.... forse attraverso un altro tipo di canale collegato ?  :-\

" I have read the discussion on gambas-it, I reply directly here, so that it
will avoid you a trip.

(And sorry for the bad translation, I don't speak Italian, thanks Google...)

For the management of small documents ... but what does that mean? Or are
> they great, or treat them?


For the parser, small documents are files < 10 MB. Beyond this, the DOM
parser might eat a lot of memory, but the Reader will parse larger files
fwithout problem (1 GB if you want).

Just to put it simply, even after an open (file), or a OpenStream (), it
> seems that they read, and yet make no parsing of the xml content, returning
> 0 in all properties. This obviously makes it a little difficult to decode
> the data ... do not you think?


When you call Open(), the file is just opened like an Gambas Open, but
nothing is loaded/parsed until you call Read(). That's why all is Null.

It 'true that, as a response to, these classes are still incomplete, and
> therefore still not stable, so better not use them.


If you found a problem, please report it, with the code and the file that
is loaded, otherwise it won't ever be stable.

I downloaded the latest version of the source of Gambas3 (4833), but the
> anomalies persist.
>
> The following is the code I'm using, and that is a purified extract of the
> original one used in pgDesigner3, for reading the configuration file, which
> worked before and now I go more.

There are some print to understand what they contain variables, but they
> are all empty.



I tried your code with the lastest revision, and with the provided file,
and here is the output :

  • ,[],[0],[],[0]

0
Read = 1
[1],[pgDesigner3  ],[1],[],[3]
1
Element::pgDesigner3
Type    Config
Version 3.0.0
Date    06/09/2012 11:56:06.713
Read = 1
[2],[APPLICATION],[1],[],[0]
2
Element::APPLICATION
Read = 1
[3],[Debug],[1],[],[0]
3
Element::Debug
Read = 2
[3],[#text],[2],[ALL],[0]
3
Text::ALL

[and so on...]

For me, it works, doesn't it ?

Regards,
Adrien.
"
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 08:06:36
Scusate l'intromissione, ma forse sarebbe meglio che, come proposto da Adrien, la discussione sia spostata qui nel forum; e prosegua direttamente tra md e Adrien, in modo da evitare problemi di traduzione e di spazi temporali  :)

@md9327
so che il tempo ti è nemico, ma nella traduzione da una lingua ad un'altra si possono perdere alcuni concetti, soprattutto se chi traduce è persona differente da chi affronta il problema.

Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 12:58:17
Si, lo sò. Avevo attivato vuott, in quanto è sempre meglio avere un solo interlocutore, un rappresentante (siamo in democrazia, no?)  ;D

Scherzi a parte, dalla risposta sembra che all'amico và tutto bene, come del resto dimostrano i risultati che ha postato.
A questo punto non capisco perchè a me non funziona...
Ho compreso che Read avvia il parsing, e in effetti così faceva prima...

Ad ogni modo, come indicato da sotema, se è un problema il passaggio posso scavalcarti vuott, e passare direttamente alla comunicazione con Adrien, anche se comunque devo necessariamente utilizzare il traduttore di google...  ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 13:01:11
Mi stà venendo un dubbio... non è che il problema è legato a librerie esterne, come ad esempio libxml?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 13:38:23
Il dubbio è + che giustificato.
libxml è la vecchia gb.xml rinominata. Infatti, come ti segnalai tempo addietro, con libxml pgdesigner funziona perfettamente.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 16 Giugno 2012, 14:38:45
Hi all.
It's me, Adrien. It's faster to reply directly here.

Citazione
Scherzi a parte, dalla risposta sembra che all'amico và tutto bene, come del resto dimostrano i risultati che ha postato. A questo punto non capisco perchè a me non funziona...

Have you got the lastest revision ? I have the #4837.
Or maybe there are errors during the compilation. Can you send here the output ?

Citazione
Ad ogni modo, come indicato da sotema, se è un problema il passaggio posso scavalcarti vuott, e passare direttamente alla comunicazione con Adrien, anche se comunque devo necessariamente utilizzare il traduttore di google... ;D

I use it too. That's very helpful.  :)
Moreover, often Italian sounds like French, so it helps me understanding.
Does anyone speak French here ? No ? Never mind... ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 14:52:33
Welcome Adrien,
I am here just to avoid a basic misunderstanding.
When md9327 starts writing pgDesigner3 the component available in Gambas to treat xml file was gb.xml. It was based on libxml library.
When you introduced the new component for xml management the old one was renamed into gb.libxml and the new one named gb.xml
The code in pgDesigner3 works perfectly with gb.libxml, but fails with gb.xml
Obviously something changed in the way xml documents and their structure is treated by gb.xml.
That has broken the project.
what I suspect is md9327 needs to switch the component into the project properties from gb.xml to gb.libxml. Otherwise he must implement a different methods and code.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 16 Giugno 2012, 15:09:15
Hi sotema,

yes, there were some changes in XmlReader, but normally, it should not be any difference in behavior between gb.libxml and gb.xml, so it is a bug.
Maybe with the full project, I can find where is the problem.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 15:13:48
Well, if md9327 agrees i can extrapolate the involved code and post it.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 16:12:19
Non ho ben capito cosa volete fare...

In effetti nell'elenco i componenti sono due: gb.xml e gb.libxml, che forniscono ciascuno le due classi XmlReader e XmlWriter.

Nel progetto pgDesigner è inclusa gb.xml, come anche nelle precedenti versioni, e fino ad alcune release precedenti di Gambas3 funzionava tutto regolarmente.

Attualmente stò verificando le differenze (svn di -r 4820:4833) tra la versione che mi risulta funzionava (4820) e l'ultima (4833), il cui risultato è in allegato a questo post.
Ho notato molte modifiche relative alla libreria, in particolare l'integrazione con i nuovi oggetti XmlDocument, XmlNode, ecc.

Dai test, e dalle differenze di risultato con le verifiche fatte da Adrien, sembra che la libreria gb.xml non faccia il suo dovere, e non emette alcun output. Ora proverò scambiando le librerie gb.xml -> gb.libxml, per vedere se funziona, e vi farò sapere...
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 16:16:55
Ciao md....

quello che sto tentando di dirti da parecchio tempo ( :evil:) è proprio questo. Se nelle proprietà del progetto, scheda componenti, selezioni gb.libxml e deselezioni gb.xml il tutto funziona "come una lippa".

Secondo Adrien però non ci sono differenze tra i due componenti che possano dare luogo al problema; indi chiede di disporre dei sorgenti di pgdesigner per analizzare l'errore.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 16:24:04
Rieccomi qui...  :D

Il problema è la libreria gb.xml !!!

Ho sostituito la libreria, e ora il codice di esempio và bene.
Ora devo provare il programma, ma confido che vada bene come prima, compresa la fase di lettura/scrittura con XmReader/XmlWriter.

La differenza tra le librerie è sostanziale, considerando che include altre classi specializzate per il trattamento dei dati xml. La libreria g.libxml ha fondamentalmente due classi principali (Reader e Writer) e un'altro paio di classi di supporto.
Probabilmente la libreria gb.xml è in fase di costruzione e, per alcune funzionalità mancano ancora i necessari agganci, come per XMlReader.
Faccio notare che anche XmlWriter funziona piuttosto male, aggiunge spazi indesiderati, interpreta male i tag, gli elementi e le properties.

Ad ogni modo, credo sia necessario far notare nella documentazione, le differenze tra le librerie, o eventualmente segnalarne lo stato. Attualmente sono tutte e due in uno stato "non finito ma stabile", ma non è la realtà, perlomeno per quanto riguarda lo scarico da repository.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 16:26:35
Ciao md....

quello che sto tentando di dirti da parecchio tempo ( :evil:) è proprio questo. Se nelle proprietà del progetto, scheda componenti, selezioni gb.libxml e deselezioni gb.xml il tutto funziona "come una lippa".

Secondo Adrien però non ci sono differenze tra i due componenti che possano dare luogo al problema; indi chiede di disporre dei sorgenti di pgdesigner per analizzare l'errore.

I sorgenti sono di pubblico dominio, in quanto sotto licenza GPL, per cui può scaricarli come vuole.

Riguardo alle libreria, l'ho scritto nel precedente post.
Riguardo le differenze, queste ci sono, e pure tante, tant'è che non funzionano...  :D

E poi... non si cambiano le librerie, rinominandole... non è corretto...  :evil:
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 16:29:59
@ Adrien

you can download the source code from:
https://pgdesigner.svn.sourceforge.net/svnroot/pgdesigner/pgdesigner/branches/3.0-alpha
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 16:32:20
E poi... non si cambiano le librerie, rinominandole... non è corretto...  :evil:
assolutamente d'accordo!
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 16:42:44
A parte quanto sopra scritto, penso che questa discussione possa chiudersi qui, se tutti sono d'accordo.
Ho provato ad avviare pgDesigner3, e sembra che ora tutto sia tornato al suo posto.

La soluzione è stata trovata, anche se per quanto riguarda la libreria gb.xml c'è ancora da discutere.

Che ne dite?

La lasciamo aperta per quest'ultima libreria?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 16:46:56
Secondo me si potrebbe aspettare che Adrien scarichi i sorgenti ed analizzi il bug. Potrebbe quindi postare qui la soluzione o eventuali richieste. Sarebbe un grosso contribut allo sviluppo di Gambas.

@Adrien
Seems that md9327 finally found the solution.
if ya agree we can keep this thread open waiting for your analisys.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 16 Giugno 2012, 18:53:35
I haven't finished my analysis, but I noticed one error in your code :

(PgXmlDocument.class, line 79)

Codice: gambas [Seleziona]
Select Case oXml.Node.Type
      '[...]
Case XmlReaderNodeType.EndElement


EndElement is not a node type, but a state, so Node.Type will never return this. You should use the State property instead :

Codice: gambas [Seleziona]
Select Case oXml.State
      '[...]
Case XmlReaderNodeType.EndElement'Ok


And, another question, are all your files encoded in UTF-8 ?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 19:06:59
I haven't finished my analysis, but I noticed one error in your code :

(PgXmlDocument.class, line 79)

Codice: gambas [Seleziona]
Select Case oXml.Node.Type
      '[...]
Case XmlReaderNodeType.EndElement


EndElement is not a node type, but a state, so Node.Type will never return this. You should use the State property instead :

Codice: gambas [Seleziona]
Select Case oXml.State
      '[...]
Case XmlReaderNodeType.EndElement'Ok


And, another question, are all your files encoded in UTF-8 ?
Welcome Adrien,
I am here just to avoid a basic misunderstanding.
When md9327 starts writing pgDesigner3 the component available in Gambas to treat xml file was gb.xml. It was based on libxml library.
When you introduced the new component for xml management the old one was renamed into gb.libxml and the new one named gb.xml
The code in pgDesigner3 works perfectly with gb.libxml, but fails with gb.xml
Obviously something changed in the way xml documents and their structure is treated by gb.xml.
That has broken the project.
what I suspect is md9327 needs to switch the component into the project properties from gb.xml to gb.libxml. Otherwise he must implement a different methods and code.
Xmlreader.State does not exists in gb.libxml

this means that the components are not equivalent and md**** have to make a lot of correction to use the new component
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 16 Giugno 2012, 19:56:52
Perdonatemi, in particolare perchè scrivo solo in Italiano...  :-\

Come indicato da sotema, pgDesigner3 funziona perfettamente con gb.libxml, mentre con gb.xml NON funziona.

Quando contenuto nel codice di pgDesigner, è derivato da un'analisi approfondita della libreria gambas, e già all'epoca avevo riscontrato problemi quando un tag veniva chiuso direttamente senza un valido contenuto. Una volta capito come aggirare il problema, ho scritto il codice presente in pgDesigner. I controlli sulla proprietà ".Node.Type", in particolare il controllo di "XmlReaderNodeType.EndElement", è dovuto proprio dalla verifica dell'apertura/chiusura dei vari elementi, in modo da catturare correttamente eventuali valori.
"EndElement" viene scatenato proprio dall'intercettazione di un tag di chiusura dopo una serie di subelementi.
I file xml che sono usati nel programma sono stati adattati in base alle possibilità della libreria, e cercando di semplificare il più possibile la loro gestione.
Sempre riguardo alle strutture xml, giornalmente tratto svariate tipologie, spesso molto complesse rispetto a quelle usate in pgDesigner, questo per dire che ho ben presente le particolarità di questo tipo di file.
XmlReader e XmlWriter semplificano molto la gestione di file xml non eccessivamente complessi, come quelli utilizzati in pgDesigner.
Per attività più complesse sarebbero invece molto utili le classi contenute nella nuova libreria gb.xml, che rispecchia molto la logica usata in altri linguaggi. Spero quanto prima venagno rese stabili. Mi complimento per il lavoro che si stà facendo su questa libreria.

Comunque, capito che il problema era la libreria, ho effettuato uno switch della stessa, e ora pgDesigner funziona nuovamente.

Riguardo al contenuto dei file, uso stringhe puramente ASCII, codificando opportunamente i caratteri fuori intervallo, più o meno come viene fatto per HTML.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 16 Giugno 2012, 20:26:45
Sotema,
no, the two component are not fully equivalent. New properties and methods were added. But the component should behaves as libxml with the same code.

This is the reason why these changes were commited on the development version. So you may expect bugs until the stable version is released.

The State/NodeType problem has been solved in the last revision.

It seems there are other problems, with XmlWriter, but I need more precisions !

Citazione
Faccio notare che anche XmlWriter funziona piuttosto male, aggiunge spazi indesiderati, interpreta male i tag, gli elementi e le properties.
Citazione
I note that XmlWriter works pretty bad, adds unwanted spaces, misread tags, elements and properties.

This is not enough for understanding where is a bug.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 16 Giugno 2012, 20:41:12
The State/NodeType problem has been solved in the last revision.
Do you mean #4838?

I note that XmlWriter works pretty bad, adds unwanted spaces, misread tags, elements and properties.

This is not enough for understanding where is a bug.
Only md**** can provide help about it. I dont know which tests he made before write the code for xml write/read inside pgdesigner.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 17 Giugno 2012, 18:41:41
The State/NodeType problem has been solved in the last revision.
Do you mean #4838?

Yes.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 17 Giugno 2012, 21:42:24
I test che ho fatto, a seguito del malfunzionamento riscontrato, sono inserite in questa discussione.

Per le prove ho anche usato il codice che ho trovato nei sorgenti di gambas3 (#4838), in particolare la lettura del semplice file trovato sempre nei sorgenti test.xml. Già il test ha riportato i problemi che ho descritto, ovviamente usando la libreria gb.xml.

Una volta modificato l'elenco delle librerie nel progetto, passando da gb.xml a gb.libxml, il tutto ha ripreso a funzionare. Questo vuol dire che in realtà esistono differenze tra le due librerie, e in particolare con le classi XmlReader e XmlWriter.

Per riassumere i test con la libreria gb.xml, e le anomalie riscontrate:

a) la classe XmlReader sembra leggere il file, senza dare errori, ma poi nel loop di lettura non rileva nulla. Solo una cosa ho notato, ovvero che Read() ritorna il valore di 7, che corrisponde al fine documento, ovvero ad eof.
b) la classe XmlWriter aggiunge spazi indesiderati nel contenuto dei tag (o elementi), formattando inoltre il file in maniera completamente diversa da come mi aspettavo, ovvero inserisce il carattere di LF dopo lo StartElement, dopo il valore dell'elemento (aggiungendo spazi in testa e in coda), e dopo lo EndElement.

Queste anomalie non accadono con le stesse classi contenute in gb.libxml !

I test sono stati effettuati sia utilizzando il codice di esempio e il file xml contenuti nei sorgenti di Gambas3 (build #4838), sia utilizzando il codice che utilizzo in pgDesigner3. Lo stesso codice e la stessa logica è stata adottata in tutte le release di pgDesigner (1, 2 e 3), e dopo vari studi per trovare il miglior modo per utilizzare la libreria.

Devo però dire, e credo di averlo già accennato, che il cambiamento di nome di una libreria, a prescindere se il codice di alcune classi sia uguale o meno, può portare a svariate conseguenza, com'è appunto e puntualmente accaduto. Questo è ovviamente un mio pensiero, ma è adottato in tutti i linguaggi conosciuti. Al massimo, se una libreria và ad implementare in todo le funzionalità di una esistente, aggiungendo magari ulteriori proprietà, credo sia più opportuno renderla obsoleta, segnalando la cosa a caratteri cubitali...  :D
Questo è ovviamente un mio pensiero, ma credo sia il caso di prenderlo in considerazione, onde evitare problemi a chi segue questo bel linguaggio che è Gambas!  :ok:
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 18 Giugno 2012, 18:11:47
I note that XmlWriter works pretty bad, adds unwanted spaces, misread tags, elements and properties.

This is not enough for understanding where is a bug.

In order to make your analisys easier i'll try to face one problem at a time
by launching the very simple program attached, once with gb.xml and once with gb.libxml component you can see the different way the file is formatted. With gb.xml the format is very ugly.
Into the tar i putted also the output produced by both gb.libxml and gb.xml
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 19 Giugno 2012, 09:51:05
Grande sotema, vedo che hai testato anche tu la cosa...  :ok:
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 19 Giugno 2012, 10:07:07
Speriamo che Adrien legga il topic, altrimento la invio alla Mailing list
  :ciao:
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 20 Giugno 2012, 09:26:57
aggiornamento,
ho inoltrato la segnalazione alla mailing-list.
Durante le prove ho però notato che aprendo i file con applicazioni che interpretano xml (ad esempio firefox) il testo è formattato correttamente.  :-\
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 20 Giugno 2012, 10:11:39
Se parli di XmlWriter, il file lo crea corretto, nel senso che tutti i tag sono aperti e chiuso nel modo corretto. Il fatto che Firefox legga correttamente il file, significa solo questo.

Se però dai un'occhiata al contenuto (cosa che hai testato anche tu stesso), vedi la differenza tra i file creati dalle due classi delle due librerie.
La vecchia libreria crea un file corretto, pulito, e non introduce nulla oltre a quello che inserisci tu da codice. La formattazione, se selezionata, viene effettuata bene, indentando correttamente i tag, seguendo la gerarchia.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 20 Giugno 2012, 11:00:44
Hi,

sorry for the time I took to reply, I have a lot of work this week (exam period).

I'm still looking for where is the bug on XmlWriter.
But for XmlReader, I still have no idea. Did you try the piece of code you gave me outside your application ?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 20 Giugno 2012, 11:29:10
Hi,

sorry for the time I took to reply, I have a lot of work this week (exam period).

I'm still looking for where is the bug on XmlWriter.
But for XmlReader, I still have no idea. Did you try the piece of code you gave me outside your application ?

No problem, and best wishes for exams...  :ok:

You can use as an example, the code contained in the source of Gambas3, folder gb.xml / .src. In these folders is a simple xml file.
The behavior of xml / Reader / XmlWriter is different between the two libraries and gb.xml gb.libxml
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 22 Giugno 2012, 23:06:54
Thanks, exams are done now, just waiting for the results ...  :)

And I finally found the problem.
The good code (that doesn't crashes libxml) should be that :

Codice: gambas [Seleziona]
Public Sub Main()
 
  Dim reader As New XmlReader
 
  reader.Open("text.xml")
 
  reader.Read()
  While Not reader.Eof
    Print reader.Node.Type
    If reader.Node.Type = XmlNode.CommentNode Then Print reader.Node.Value
    reader.Read()
  Wend
 
 
End


I've got this with gb.xml :

Codice: [Seleziona]
8
2
2
2
6
3
 Hello


... and this with gb.libxml :

Codice: [Seleziona]
1
3
1
3
15
8
 Hello
14
15

Numbers (and so readed elements) are missing, now I've just to find why.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 23 Giugno 2012, 16:30:56
it is evident that the error was present. The class is different in the two libraries, and it is likely that changes were made to create the anomaly.
I have not had time to analyze the source code of the XmlReader / XmlWriter, but if you wish, I can look at it to find the problem.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 23 Giugno 2012, 21:48:26
Too late. I found what the problem was. :)

I solved it in the last revision (#4855 I think), and also updated the test module and the XML test file, so that they are compatible with libxml and more explicit :

Codice: gambas [Seleziona]
' Gambas module file

Public Sub Main()
  
  Dim reader As New XmlReader
  
  reader.Open("text.xml")
  reader.Read()
  While Not reader.Eof
    Print reader.Node.Type;;
    Select Case reader.Node.Type
      Case XmlReaderNodeType.Element
        Print "element"
      Case XmlReaderNodeType.Attribute
        Print "attribute"
      Case XmlReaderNodeType.Text
        Print "text"
      Case XmlReaderNodeType.Comment
        Print "comment"
      Case XmlReaderNodeType.EndElement
        Print "endelement"
      Default
      Print ""
    End Select
    reader.Read()
  Wend
  
  
End


Codice: xml [Seleziona]
<?xml version="1.0"?>
<toto machin="toto">Hello<truc>Bouh</truc><!-- Hello --></toto>


Here are the new results on my machine, first with gb.libxml :
Codice: [Seleziona]
1 element
3 text
1 element
3 text
15 endelement
8 comment
15 endelement

.. and then with gb.xml :

Codice: [Seleziona]
1 element
2 text
1 element
2 text
6 endelement
3 comment
6 endelement

Results are the same, so I think the bug is solved, please tell me if you have the same behaviour with the last revision.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 25 Giugno 2012, 19:06:47
Ok, I get the new version, and I check the changes.
thanks
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 25 Giugno 2012, 19:46:49
I checked out the new version (build 4859), but I found another problem.
Following the test with the code I used for previous tests, I noticed that the tag XmlReaderNodeType.Element is not detected, causing errors in reading the names, and consequently the associated values​​.
The tag XmlReaderNodeType.EndElement, instead is detected.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 25 Giugno 2012, 19:55:51
I solved it in the revision 4860.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 26 Giugno 2012, 00:37:13
Ok, I get the new version, and I check the changes.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 26 Giugno 2012, 18:48:00
I downloaded the build 4860.
I ran the tests and now seems to work, reading and returning the tags and values ​​in the xml file.
I found other problems:
1) The Close () method no longer exists
2) the tag names are returned with unwanted spaces, which are not contained in the xml file. Needless to say, this would result in the execution of a Trim () of the strings, with consequent additional work.

I'm sorry for all this work, but I think it advisable to fix the library, to make it fully functional.  :-\
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 27 Giugno 2012, 14:25:25
Citazione
I'm sorry for all this work, but I think it advisable to fix the library, to make it fully functional.
You haven't to be sorry for this. I should thank you for your bug reports. :ok:

I made some changes in the last revision (#4684), can you try this out ?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 27 Giugno 2012, 18:30:47
I downloaded the build 4864 (not 4684...  :D ), and noted that:
1) The Close () method now works  :ok:
2) the anomalous spaces are still reproduced  :-\
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 27 Giugno 2012, 19:08:51
The spaces problem is in your code.
For Example, I replaced this line :

Codice: gambas [Seleziona]
Print "Element::" & reader.Node.Name, reader.Node.Value


... by this one :

Codice: gambas [Seleziona]
Print "Element::" & reader.Node.Name & reader.Node.Value


And there isn't spaces anymore.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 28 Giugno 2012, 00:29:51
No.

Taking the example of loading file pgdesigner.conf (attached), using the code:
Codice: [Seleziona]
Static Public Sub Main()
  Dim reader As New XmlReader
  Dim writer As New XmlWriter
  Dim arr As String[]
  reader.Open("/home/luigi/tmp/pgdesigner3.conf")
  While (Not reader.Eof)
    arr = ["Type=" & reader.Node.Type,
           "Name=" & reader.Node.Name,
           "Value=" & reader.Node.Value,
           "Depth=" & reader.Node.Depth,
           "Attributes=" & reader.Node.Attributes.Count]
    Print "Row[" & arr.Join("],[") & "]"
    Select Case reader.Node.Type
      Case XmlReaderNodeType.Element
        Print "Element[name=[" & reader.Node.Name & "], value=[" & reader.Node.Value & "]]"
        For Each reader.Node.Attributes
          Print "Attribute[name=[" & reader.Node.Name & "], value=[" & reader.Node.Value & "]]"
        Next
      Case XmlReaderNodeType.EndElement
        Print "EndElement[]"
      Case XmlReaderNodeType.Text
        Print "Text[value=[value=[" & reader.Node.Value & "]]"
    End Select
    reader.Read()
  Wend
  reader.Close()

the second and the third line shows:

with gb.xml
Codice: [Seleziona]
Row[Type=1],[Name=pgDesigner3  ],[Value=],[Depth=1],[Attributes=3]
Element[name=[pgDesigner3  ], value=[]]

with gb.libxml
Codice: [Seleziona]
Row[Type=1],[Name=pgDesigner3],[Value=],[Depth=1],[Attributes=3]
Element[name=[pgDesigner3], value=[]]
that, as you can see, gb.xml adds a space at the end of string "pgDesigner3".
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 28 Giugno 2012, 20:28:37
Oops, sorry, I wasn't looking at the good element.
It works for me with the revision #4868.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 02 Luglio 2012, 14:02:07
 >:( :evil:

 :D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 02 Luglio 2012, 15:02:00
...and what about the "Ident" behaviour?
http://www.gambas-it.org/smf/index.php?topic=2179.msg24009#msg24009
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 02 Luglio 2012, 18:28:18
Oops, sorry, I wasn't looking at the good element.
It works for me with the revision #4868.

Ok, now seems to work XmlReader.  :ok:
For XmlWriter I do more testing...

The tests I made them with build 4882.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 02 Luglio 2012, 18:38:49
The writing does not work.

Enclosed I send you two files:
1) pgdesigner3.conf is the original file, I use to read the configuration of my program
2) pgdesigner3.conf2 is the file that is created by the XmlWriter (gb.xml).

With the library gb.libxml the second file is created exactly equal to the first. With gb.xml the file is saved with the same structure, but with incorrect indentation and spaces are not required.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 03 Luglio 2012, 19:18:33
Is it better with the last revision ?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 03 Luglio 2012, 21:59:52
It is ok for me with rev. 4891
thanks Adrien
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 04 Luglio 2012, 00:01:18
Is it better with the last revision ?

I still have to download it ...
The last was the build # 4882.  :-\

Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 04 Luglio 2012, 00:27:11
Is it better with the last revision ?

I still have to download it ...
The last was the build # 4882.  :-\



Build #4893... PERFECT!!!  :ok:

Now the input files and output are identical. XmlWriter writes exactly what he reads XmlReader.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 04 Luglio 2012, 08:15:52
Wanting to be precisely accurate, perhaps finicky, on the first line xmlwriter should indicate the Encoding as for the standard.
Anyway...it works. :2birre:
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 07 Luglio 2012, 15:38:30
Hello Procopy,

After testing the latest changes, I noticed a big difference in starting the program, depending on if you use the library gb.libxml or gb.xml.
With gb.xml, the program will start after several seconds, as if something heavy load.
With gb.libxml, the startup is faster.
In both cases, the program performs a number of readings in the xml configuration files.
You can verify this anomaly?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 08 Luglio 2012, 16:54:16
Outch ... I noticed that too. I see with the Gambas profiler that around 8 seconds are taken only by xmlreader.read(). I know that the XmlReader class is not made for little configuration files (XmlDocument and XmlExplorer are very faster for this), but there is obviously a huge problem.

I'm still running valgrind to find what the problem is, but even on my fastest CPU, it takes a long ...  :sleepy:
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 08 Luglio 2012, 17:37:40
I made a few more optimizations and solved a bug with UTF-8 text. With the last revision this is really faster on my machine :

Read() Non-optimized : 8139546 µsec (8.1 sec) / 1336 calls
Read() Optimized : 53112 µsec (0.05 sec) / 1336 calls

Please tell me if it is better for you too.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 08 Luglio 2012, 18:26:04
Which version?
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 08 Luglio 2012, 19:17:37
This is the revision 4910.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 08 Luglio 2012, 19:42:41
I downloaded the 4912 version.
Now the speed is equal with the two libraries.
I noticed, however, in the header of the xml file is no longer stored the encoding:
Codice: [Seleziona]
<?xml version="1.0" encoding="UTF-8"?>   #with gb.libxml

<?xml version="1.0"?>   #with gb.xml
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 08 Luglio 2012, 19:45:49
...as i said in rplay #67  :P
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 08 Luglio 2012, 21:35:54
This is solved in the last revision (#4915).
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 08 Luglio 2012, 21:50:52
thanks.

Maybe another problem, maybe i misunderstood the doc:

XmlElement.GetAttribute (gb.xml)
Function GetAttribute ( Name As String ) As String
Returns the attribute Name.

Should return the Value of Attribute "Name"?

With the following code:

Codice: gambas [Seleziona]
Public Sub Main()
Dim oRoot As XmlElement
Dim oDoc As XmlDocument
Dim iVar As Integer
Dim oReader As XmlReader
  oDoc = New XmlDocument
  oDoc.Open("language")
  oRoot = oDoc.Root
  Debug oRoot.Name
  Debug oRoot.Children.Count
  For iVar = 0 To oRoot.ChildElements.Max
    Print oRoot.ChildElements[iVar].GetAttribute("name")
    Print oRoot.ChildElements[iVar].GetAttribute("code")
    Print oRoot.ChildElements[iVar].GetAttribute("region")
  Next
End


i got
name
code
region

while i expect:
Milan
MI
Lombardia

see the attached file.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 08 Luglio 2012, 22:38:05
You're right, this should return the value of the attribute. I really hate this kind of stupid bugs...
This is solved in the revision #4917.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 09 Luglio 2012, 08:28:23
Rev #4919 it's ok
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 09 Luglio 2012, 21:51:53
Hi Prokopy,
I have a bad new for you.
If you try to read an non existing Attribute a signal 11 occurs. (Rev. #4925)
Use the following code with the file cities attached in my previous post:
Codice: gambas [Seleziona]
Public Sub Main()
Dim oRoot As XmlElement  
Dim oDoc As XmlDocument  
Dim iVar As Integer  
Dim oReader As XmlReader  
 oDoc = New XmlDocument  
 oDoc.Open("cities.txt")  
 oRoot = oDoc.Root  
 Debug oRoot.Name  
 Debug oRoot.Children.Count  
 For iVar = 0 To oRoot.ChildElements.Max  
   Print oRoot.ChildElements[iVar].GetAttribute("name")  
   Print oRoot.ChildElements[iVar].GetAttribute("cod")  ' should be "code"
   Print oRoot.ChildElements[iVar].GetAttribute("region")  
 Next  
    
End

Attached the debugger output.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: Prokopy - 10 Luglio 2012, 00:29:17
Hum, I think there is a mistake in your code. This line does not crashes :

Codice: gambas [Seleziona]
Print oRoot.ChildElements[iVar].GetAttribute("cod")


... but this one does :

Codice: gambas [Seleziona]
Print oRoot.ChildElements[iVar].Attributes["cod"]


We can see in the debugger output that the CElementAttributes_get method is called, not the CElement_getAttributes one.

Anyway, this is solved in the revision #4927. Thanks. :)
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 10 Luglio 2012, 07:27:39
Hmmm, yes i made some bad cut & paste!

Thanks a lot.
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 10 Luglio 2012, 12:43:26
sotema... You are always the same ...  ;D
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: sotema - 10 Luglio 2012, 15:53:38
yep  :-[
Titolo: Re: Errore con i tag XmlWriter in gb.xml
Inserito da: md9327 - 31 Luglio 2012, 19:15:11
I have a small request to make to our friend Procopy.
In the production of an xml file, the XmlWriter (gb.xml and gb.libxml) creates a file with an indentation is not perfectly aligned. The closing tag does not respect the position initiated by the opening tag.
You can make sure to properly align the tags?
Obviously this is just a request you aesthetic ...

Thanks!!!  ;)