I'm trying to output data from an Access table as XML.
The output looks like example A
, what is required looks like example B
.
My current code to do this is shown below at example C
If anyone could help it would be greatly appreciated.
Example A:
<inlineData inlineDataId="1">
<date>24 AUG, 2009</date>
<regis>123456</regis>
<Field15>10000</Field15>
<Field17>10000</Field17>
<Field19>0</Field19>
<Field21>0</Field21>
<rego1>123123</rego1>
<rego2>123124</rego2>
<rego3>123125</rego3>
<rego4/>
<rego5/>
</inlineData>
Example B:
<inlineData inlineDataId="1">
<date>24 AUG, 2009</date>
<regis>123456</regis>
<Field15>10000</Field15>
<Field17>10000</Field17>
<Field19>0</Field19>
<Field21>0</Field21>
<vehOwned>
<rego1>123123</rego1>
<rego2>123124</rego2>
<rego3>123125</rego3>
<rego4/>
<rego5/>
</vehOwned>
</inlineData>
Example C:
''// next we go through each record in the recordset, these elements are named
''// according to the field name.
''// note Nz(varItem.Value, "-") in the code - null values here can
''// cause problems on occasion...
rs.MoveFirst
While rs.EOF = False
Dim counter
counter = 1
Do While Not rs.EOF
strXML = strXML & _
"<dataSource>" & vbCrLf & _
"<" & strRoot & counter & "'>" & vbCrLf
For Each varItem In rs.Fields
strXML = strXML & " <" & varItem.Name & ">" & _
Trim(Nz(varItem.Value, "")) & "</" & varItem.Name & ">" & vbCrLf
Next varItem
strXML = strXML & "</inlineData>" & "</dataSource>" & vbCrLf
rs.MoveNext
counter = counter + 1
Loop
Wend