-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap2Xml.bas
More file actions
68 lines (62 loc) · 1.49 KB
/
Map2Xml.bas
File metadata and controls
68 lines (62 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=5.9
@EndOfDesignText@
'v1.00
Sub Class_Globals
Private builder As XMLBuilder
End Sub
Public Sub Initialize
End Sub
Public Sub MapToXml (m As Map) As String
For Each k As String In m.Keys
builder = builder.create(k)
HandleElement("", m.Get(k))
Exit
Next
builder = builder.up
#if B4J or B4A
Dim props As Map
props.Initialize
props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
props.Put("indent", "yes")
Return builder.asString2(props)
#else
Return builder.AsString
#end if
End Sub
Private Sub HandleMapElement (m As Map)
Dim attributes As Map = m.Get("Attributes")
If attributes.IsInitialized Then
For Each attr As String In attributes.Keys
builder.attribute(attr, attributes.Get(attr))
Next
If m.ContainsKey("Text") Then builder.text(m.Get("Text"))
m.Remove("Attributes")
m.Remove("Text")
End If
For Each k As String In m.Keys
Dim value As Object = m.Get(k)
HandleElement(k, value)
Next
End Sub
Private Sub HandleElement (key As String, value As Object)
If value Is Map Then
If key <> "" Then builder = builder.element(key)
HandleMapElement(value)
If key <> "" Then builder = builder.up
Else if value Is List Then
HandleListElement (key, value)
Else
builder = builder.element(key)
builder = builder.text(value)
builder = builder.up
End If
End Sub
Private Sub HandleListElement (key As String, lst As List)
For Each value As Object In lst
HandleElement(key, value)
Next
End Sub