It’s been a while since I released anything into the community, so I’m offering up this little class I created because I didn’t have the patience to twiddle with the built-in xml classes and I wanted a simple api for creating some xml. It is free as in beer and it’s too simple to request attribution. Just tweak it and use it as desired. Any comments and suggestions are welcome.
Download it from: http://www.telios.com/xojo/projects/tscXMLBuilder.xojo_binary_code
Drag it into a project and use it like
dim x as new tscXMLBuilder
dim s as string
x.tagBegin("catalog")
x.tagBegin("cd")
x.tag("title")= "Empire Builder"
x.tag("artist")= "Bob Dylan"
x.tag("company")= "Columbia Records"
x.tagEnd("cd")
x.tagBegin("cd")
x.tag("title")= "Hide Your Heart"
x.tag("artist")= "Bonnie Tyler"
x.tag("company")= "CBS Records"
x.tagEnd("cd")
x.tagEnd("catalog")
s= x.text
It will produce
<catalog>
<cd>
<title>Empire Builder</title>
<artist>Bob Dylan</artist>
<company>Columbia Records</company>
</cd>
<cd>
<title>Hide Your Heart</title>
<artist>Bonnie Tyler</artist>
<company>CBS Records</company>
</cd>
</catalog>
Another example would be
dim rs as recordset = db.sqlselect(...)
dim x as new tscXMLBuilder
dim i as integer
dim f as DatabaseField
x.tagBegin("records")
while not rs.EOF
x.tagBegin("record")
for i = 1 to rs.FieldCount
f = rs.idxfield(i)
x.tag(f.name) = f.StringValue
next
x.tagEnd("record")
wend
x.tagEnd("records")
Cheers.