diff --git a/gb.xml/src/gb.xml/.src/MTest.module b/gb.xml/src/gb.xml/.src/MTest.module index 6e8b3e6a6..b25dc19b5 100644 --- a/gb.xml/src/gb.xml/.src/MTest.module +++ b/gb.xml/src/gb.xml/.src/MTest.module @@ -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() diff --git a/gb.xml/src/gb.xml/.src/XmlWriter.class b/gb.xml/src/gb.xml/.src/XmlWriter.class index 25c0174ae..78d2f8e6c 100644 --- a/gb.xml/src/gb.xml/.src/XmlWriter.class +++ b/gb.xml/src/gb.xml/.src/XmlWriter.class @@ -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", "") & " " + sData &= ">" & Value & " " Else sData &= " />" Endif @@ -121,9 +122,11 @@ Public Sub EndElement() Write(" />" & If($indent, "\n", ""), True) 'Pas de contenu $TagEnded = True Else - Write("") + Write("" & 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("",, 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("", 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("", True, True) + $lastWasElement = True End