Exporting to XML, need headers and footers (1 Viewer)

topdesk123

Registered User.
Local time
Yesterday, 19:57
Joined
Mar 28, 2013
Messages
52
Good morning all! I apologize in advance for cross posting, but I was't getting any response on the other forum.

I am using this to write out an XML file (found it on the web):

Code:
Dim tostate3 As AdditionalData
    'Dim objOrderDetailsInfo As AdditionalData
    
    Set tostate3 = Application.CreateAdditionalData
    

    Set tostate3 = tostate3.Add("state3")
   
    
    ' Export the contents of the tostate3 table.
    Application.ExportXML ObjectType:=acExportTable, DataSource:="tostate3", _
                          DataTarget:="c:\clients\joe dean\mydata.xml", _
                          AdditionalData:=tostate3
The data is just fine, here's a bit of it:
Code:
< tostate3>
< e01_01>15-1932</e01_01>
< e01_02>COptions</e01_02>
< e01_03>Northwest Trips</e01_03>
< e01_04>2.1</e01_04>
< e02_01>99-v007</e02_01>
< e02_04>30</e02_04>
< e02_05>60</e02_05>
< E02_06>105</E02_06>
< E02_07>135</E02_07>
< E02_08>225</E02_08>
< E02_09>290</E02_09>
< E02_10>360</E02_10>
< e02_12>4</e02_12>
< E02_20>390</E02_20>
< E03_01>0</E03_01>
< E03_02>0</E03_02>
< e04_03>61106110</e04_03>
< e05_02>10022015221800</e05_02>
< e05_04>10022015221800</e05_04>
< e05_05>10022015221800</e05_05>
< e05_06>10022015221800</e05_06>
< e05_07> </e05_07>
< e05_09> </e05_09>
< e05_10> </e05_10>
< e05_11>10022015222600</e05_11>
< e05_13>10022015222600</e05_13>
< E06_08> </E06_08>
< E06_11>-10</E06_11>
< E06_12>-10</E06_12>
< E06_13>-10</E06_13>
< E06_16>  </E06_16>
< E07_01>-25</E07_01>
< E07_34>-25</E07_34>
< E07_35>-25</E07_35>
< E08_05>1120</E08_05>
< E08_06>0</E08_06>
< E08_07>1135</E08_07>
< e08_11>29610</e08_11>
< e08_12>007</e08_12>
< e08_15>44041</e08_15>
< E09_04>-25</E09_04>
< e09_11>-25</e09_11>
< e09_12>-25</e09_12>
< e09_13>-25</e09_13>
< e09_14>-25</e09_14>
< E09_15>-25</E09_15>
< E09_16>-25</E09_16>
< E10_01>-25</E10_01>
< E10_03>-25</E10_03>
< E10_08>-25</E10_08>
< E10_09>-25</E10_09>
< E11_01>-25</E11_01>
< E11_02>-25</E11_02>
< E11_03>-25</E11_03>
< E12_01>-25</E12_01>
< E12_19>-25</E12_19>
< E14_04> </E14_04>
< E14_05> </E14_05>
< E14_07> </E14_07>
< E14_11> </E14_11>
< E14_15> </E14_15>
< E14_16> </E14_16>
< E14_17> </E14_17>
< E20_02>-25</E20_02>
< e20_10>4825</e20_10>
< e20_14>-25</e20_14>
< e20_16>-25</e20_16>
< e20_17>-25</e20_17>
< E22_01>-25</E22_01>
< E22_02>-25</E22_02>
< E23_09></E23_09>
< /tostate3>
< /dataroot>
However, I need a header and footer ( I don't know what else to call them) for each group like this:
Code:
< Header>
  <Record>          
[COLOR=#b22222]<e01>[/COLOR]
< e01_01>15-0449</e01_01>
< e01_02>COptions</e01_02>
< e01_03>Northwest Trips</e01_03>
< e01_04>2.1</e01_04>
[COLOR=#b22222]</e01>[/COLOR]
< e02>
< e02_01>99-v007</e02_01>
< e02_04>30</e02_04>
< e02_05>60</e02_05>
< E02_06>105</E02_06>
< E02_07>135</E02_07>
< E02_08>225</E02_08>
< E02_09>290</E02_09>
< E02_10>360</E02_10>
< e02_12>R-2</e02_12>
< E02_20>390</E02_20>
< /e02>
< e03>
< E03_01>425</E03_01>
< E03_02>0</E03_02>
< /e03>
< e04>
< e04_03>61106110</e04_03>
< /e04>
< e05>
< e05_02>03012015000200</e05_02>
< e05_04>03012015000200</e05_04>
< e05_05>03012015000200</e05_05>
< e05_06>03012015000200</e05_06>
< e05_07> </e05_07>
< e05_09> </e05_09>
< e05_10> </e05_10>
< e05_11>03012015001600</e05_11>
< e05_13>03012015001600</e05_13>
< /e05>
< e06>
< E06_08></E06_08>
< E06_11>-10</E06_11>
< E06_12>-10</E06_12>
< E06_13>-10</E06_13>
< E06_16>  </E06_16>
< /e06>
    </Record>
< /Header>
< /EMSDataSet>
I also need to add the <record>, </Record> and <header>, </Header> at the beginning and end of the file. I don't understand much of this and am soaking up everything I can read on it. Any assistance will be greatly appreciated.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:57
Joined
Sep 12, 2006
Messages
15,634
I tend to manage xml file production by hand

Code:
 sub outputxmlbody
 writeheaderstarttag
 writebody
 'which can be
 'for each fld in body.fields
 '  write open tag
 '  write detail
 '  write closetag
 'next
 writeheaderclosetag
end sub
   
so given a table/query, you can iterate a record set - something like this
  
 outputxmlfileheader
 while not rst.eof
      outputxmlbody
      'call sub to wrap the detail as required
      rst.movenext
 wend
 outputxmlfilefooter
hope this helps
 

topdesk123

Registered User.
Local time
Yesterday, 19:57
Joined
Mar 28, 2013
Messages
52
Thank you Dave! (Not Gemma the dog):)

I'm a bit confused on how to use this (my own ignorance).
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:57
Joined
Sep 12, 2006
Messages
15,634
well, given your query, if you go through the data in code a line at a time, you will have records for

<e01>
<e02>
<e03>
etc


so for each different <enn> you need to

Code:
 first output <enn> tag
 then output the <enn> lines
 finally output </enn> tag

I imagine you can do this with a style sheet or transformation, but I am not competent with them.
 

Rx_

Nothing In Moderation
Local time
Yesterday, 20:57
Joined
Oct 22, 2009
Messages
2,803
I just noticed this site can't search on the string XML. However if XML is in the Tag it does work.

Here are just a couple more links about XML that might be worth your time.

http://www.access-programmers.co.uk/forums/showthread.php?t=265606

http://www.access-programmers.co.uk/forums/showthread.php?t=242332

http://www.access-programmers.co.uk/forums/showthread.php?t=243732

http://www.access-programmers.co.uk/forums/showthread.php?t=242458

http://www.access-programmers.co.uk/forums/showthread.php?t=264297

If MSSQL Server is being used on the back-end, there might be some more options.
 

Users who are viewing this thread

Top Bottom