Autore Topic: Errore con i tag XmlWriter in gb.xml  (Letto 10825 volte)

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #45 il: 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

Offline Prokopy

  • Gamberetto
  • *
  • Post: 19
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #46 il: 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.

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #47 il: 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.

Offline Prokopy

  • Gamberetto
  • *
  • Post: 19
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #48 il: 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.
« Ultima modifica: 24 Giugno 2012, 14:08:27 da Prokopy »

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #49 il: 25 Giugno 2012, 19:06:47 »
Ok, I get the new version, and I check the changes.
thanks

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #50 il: 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.

Offline Prokopy

  • Gamberetto
  • *
  • Post: 19
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #51 il: 25 Giugno 2012, 19:55:51 »
I solved it in the revision 4860.

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #52 il: 26 Giugno 2012, 00:37:13 »
Ok, I get the new version, and I check the changes.

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #53 il: 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.  :-\

Offline Prokopy

  • Gamberetto
  • *
  • Post: 19
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #54 il: 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 ?

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #55 il: 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  :-\

Offline Prokopy

  • Gamberetto
  • *
  • Post: 19
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #56 il: 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.

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #57 il: 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".

Offline Prokopy

  • Gamberetto
  • *
  • Post: 19
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #58 il: 28 Giugno 2012, 20:28:37 »
Oops, sorry, I wasn't looking at the good element.
It works for me with the revision #4868.

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Errore con i tag XmlWriter in gb.xml
« Risposta #59 il: 02 Luglio 2012, 14:02:07 »
 >:( :evil:

 :D