[GB.XML]
* BUG: Solved a few bugs with the indentation in XmlWriter. git-svn-id: svn://localhost/gambas/trunk@4889 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
44f7bd086b
commit
bbe2044823
2 changed files with 25 additions and 11 deletions
|
@ -8,15 +8,21 @@ Dim writer As New XmlWriter
|
|||
writer.Open("", True)
|
||||
|
||||
|
||||
writer.StartElement("toto", ["titi", "tutu", "truc"], "tata", "http://")
|
||||
writer.StartElement("toto")
|
||||
writer.StartElement("titi")
|
||||
writer.Attribute("tutu", "toto", "muche", "ftp://")
|
||||
|
||||
writer.Text("hello")
|
||||
writer.EndElement()
|
||||
writer.StartElement("titi")
|
||||
writer.Text("hello")
|
||||
writer.EndElement()
|
||||
writer.Element("toto", "hello")
|
||||
writer.StartElement("titi")
|
||||
writer.Text("hello")
|
||||
writer.EndElement()
|
||||
writer.Element("toto", "hello")
|
||||
writer.StartElement("titi")
|
||||
writer.Text("hello")
|
||||
writer.EndElement()
|
||||
writer.Comment("Test")
|
||||
writer.CDATA("Test")
|
||||
writer.Comment("test")
|
||||
writer.PI("tut", "toto")
|
||||
|
||||
writer.EndDocument()
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ Private $indent As Boolean
|
|||
Private $TagEnded As Boolean = True
|
||||
|
||||
Private $opened As Boolean = False
|
||||
Private $lastWasElement As Boolean = False
|
||||
|
||||
Private PileElements As New String[]
|
||||
|
||||
|
@ -34,7 +35,7 @@ Private Sub Write(Data As String, Optional IgnoreIndent As Boolean, Optional Lin
|
|||
|
||||
If Not $opened Then Error.Raise("Document not opened")
|
||||
LineBreak = LineBreak And $indent
|
||||
If $indent And Not IgnoreIndent Then Data = String$(PileElements.Count, "\t") & Data
|
||||
If $indent And Not IgnoreIndent Then Data = String$(PileElements.Count, " ") & Data
|
||||
If LineBreak Then Data &= "\n"
|
||||
If $stream Then
|
||||
Write #$stream, Data
|
||||
|
@ -67,7 +68,7 @@ Public Sub Element(TagName As String, Optional Value As String, Optional Prefix
|
|||
Endif
|
||||
sData = "<" & TagName & Xmlns
|
||||
If Value Then
|
||||
sData &= ">" & If($indent, "\n", "") & Value & If($indent, "\n", "") & "</" & TagName & "> "
|
||||
sData &= ">" & Value & "</" & TagName & "> "
|
||||
Else
|
||||
sData &= " />"
|
||||
Endif
|
||||
|
@ -121,9 +122,11 @@ Public Sub EndElement()
|
|||
Write(" />" & If($indent, "\n", ""), True) 'Pas de contenu
|
||||
$TagEnded = True
|
||||
Else
|
||||
Write("</" & tag & ">")
|
||||
Write("</" & tag & ">" & If($indent, "\n", ""), Not $lastWasElement)
|
||||
Endif
|
||||
|
||||
$lastWasElement = True
|
||||
|
||||
End
|
||||
|
||||
Public Sub Attribute(Name As String, Value As String, Optional Prefix As String, Optional URI As String)
|
||||
|
@ -151,16 +154,19 @@ Public Sub Comment(Comment As String)
|
|||
Endif
|
||||
Write("<!--" & Comment & "-->",, True)
|
||||
|
||||
$lastWasElement = False
|
||||
|
||||
End
|
||||
|
||||
Public Sub Text(Text As String)
|
||||
|
||||
|
||||
If Not $TagEnded Then
|
||||
Write(">" & If($indent, "\n", ""), True)
|
||||
Write(">", True)
|
||||
$TagEnded = True
|
||||
Endif
|
||||
Write(Text, True)
|
||||
$lastWasElement = False
|
||||
|
||||
End
|
||||
|
||||
|
@ -172,6 +178,7 @@ Public Sub CDATA(data As String)
|
|||
Endif
|
||||
Write("<![CDATA[" & data & "]]>", True)
|
||||
|
||||
$lastWasElement = False
|
||||
End
|
||||
|
||||
Public Sub PI(Target As String, Content As String)
|
||||
|
@ -182,6 +189,7 @@ Public Sub PI(Target As String, Content As String)
|
|||
Endif
|
||||
Write("<?" & Target & " " & Content & "?>", True, True)
|
||||
|
||||
$lastWasElement = True
|
||||
End
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue