[Gambas-user] Error with XmlWriter tag in gb.xml
Ru Vuott
vuott at ...325...
Thu Jun 14 00:53:02 CEST 2012
Hello Benoit,
an user of Gambas-it.org Community ask me to write to you about a possible error with XmlWriter tag in gb.xml.
He says that he found a problem, linked to the library gb.xml, especially with XMLWriter (but there is probably something with XMLReader).
Example, he has to write an xml file, with a series of nested tags, where most of the elements have a single value (Text), such as:
<Tags>
<Tag1>valore</Tag1>
<Tag2>valore</Tag2>
</Tags>
As can be seen, Tag1 and Tag2 have a value, and this is enclosed between the opening of the tag "<Tag1>", and its closure "/ Tag1>".
Up to now he believes the logic is straightforward, and he says that this has so far been adopted in all its applications, including pgDesigner (xml file that reads a lot).
After downloading the latest version of Gambas3 in source code form, now is the 4827, he found that the reading is something wrong (still unclear), while the writing has an error, that he has encountered in the source class XmlWriter.class, of which he brings the party to the problem:
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
The user says that the code applies faulty logic, or at least partly by an assumption is not entirely correct. The tag is opened and closed by the state of the variable $ TagEnded, not taking into account that there may be a text value in the middle. This causes the incorrect writing of tags, as seen below:
<Tag1valore />
<Tag2valore />
it combines the name of the tag with the value itself.
The sequence in which the tag is opened and closed, and associated with this value is as an example:
DIM oXml As XmlWriter
...
oXml.StartElement("Tag1")
oXml.Text("valore")
oXml.EndElement()
With version 3.1.1 it worked, but now our friend user says that with the latest updates do not go anymore. I do not know if the 3.1.1, the later builds contain all the same problem, but certainly the 4827.
Well, this is what he wrote and asked me to tell you. I'll communicate to him your answer to this.
Bye
Vuotttttt
More information about the User
mailing list