Results 1 to 11 of 11
  1. #1
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Horrible data structure need to output to XML file so confused

    Good morning all!



    This is a followup post to my previous question regarding exporting Access to XML. I've attached a copy of the database and here is the desired output (FROM THE TOSTATE3 TABLE):XML_ToState.zip
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <EMSDataSet xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance">
    <Header>
      <Record>          
    <e01>
    <e01_01>15-0449</e01_01>
    <e01_02>COptions</e01_02>
    <e01_03>Northwest Trips</e01_03>
    <e01_04>2.1</e01_04>
    </e01>
    <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 have tried many things, and cannot for the life of me figure out how to add the start and end tags between groups (ie. <e01> and </e01) - I can export the xml fine - but of course the extra tags do not show up. Any thoughts? NOTE: I did NOT create this db, I inherited it. The XML needs to be uploaded to a state database monthly. I thank you in advance and wish you all a VERY HAPPY FRIDAY!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Are you using the export wizard?

    An HTML file is just a text file. Code can construct text file - line by line. This is what you will have to do if you want to do something the wizard cannot accomplish.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    That's what I was afraid of. No the wizard doesn't add the tags that are needed. I'm trying to figure out right now how to write it out to a file with the extra tags. Thanks for replying again June!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Will need to open recordset of data and loop through records and write to text file. Review http://www.tek-tips.com/faqs.cfm?fid=3767
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I took a different approach than June. Since you have the code to create the XML file, I edit that file.

    If the 2nd line of the XML file does not begin with "<dataroot", you will have to edit the code.

    So the code saves the XML file, adds the tags by reading the original XML file, writing to a 2nd XML file (with a _1) suffix.
    Then the code deletes the original XML file and renames the new file to the old file name.

    The code executes with no errors on my computer. Hopefully it does on you computer also.



    You might also consider converting the mdb to an accdb format dB.

  6. #6
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    WOW! THANK YOU STEVE!! That's amazing! I looked through the code and it is SO over my head. Thanks again!

    Gina
    Attached Files Attached Files
    Last edited by Gina Maylone; 11-22-2015 at 01:10 AM.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You're welcome.... but it's not that hard.

    Start by opening the two files for input and output.
    Read/write lines until it is time to add the headers
    Then there is a Do Loop until end of input file
    Determine when to write (add) the opening and closing tags using If statements to know exactly when to insert lines
    Write the lines that already exist
    Then write the closing commands.
    Delete the original xml file
    Rename the new file to the original xml filename

    Easy as falling off a log .... (pun intended)

  8. #8
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    :d:d:d

  9. #9
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Steve,

    How do I change <dataroot xmlnsd="urn:schemas-microsoft-comfficedata" generated="2015-11-23T15:42:46"> to <EMSDataSet xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance">? Do I just need to do a replace within the text file?

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Tried to download your accdb file, but it was corrupt???
    I imported the tables/code from the mdb file.

    Try
    Code:
        'read lines
        Line Input #RF, TextLine   '<?xml version="1.0" encoding="UTF-8"?>
        Print #WF, TextLine
        Line Input #RF, TextLine   '<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2015-11-20T18:29:45">
        '    Print #WF, TextLine
        Print #WF, "<EMSDataSet xmlns:xsd=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsi= ""http://www.w3.org/2001/XMLSchema-instance"" > """
    Then at the bottom of the code, change
    Code:
        'print closing record tag
        Print #WF, "</Record>"
        'print closing header tag
        Print #WF, "</Header>"
        'print closing dataroot tag
    '    Print #WF, TextLine            ' "</dataroot >"
        Print #WF, "</EMSDataSet>"
    See attached zip

  11. #11
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    You never cease to amaze me Steve! If you're in Minnesota on Thursday please stop by for Thanksgiving dinner! THANK YOU!!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Output Report to PDF file
    By jcc285 in forum Reports
    Replies: 4
    Last Post: 03-30-2015, 10:54 AM
  2. Replies: 4
    Last Post: 04-05-2012, 01:00 PM
  3. Replies: 1
    Last Post: 11-28-2011, 11:44 AM
  4. output file name
    By AdrianoG87 in forum Reports
    Replies: 4
    Last Post: 11-03-2011, 06:20 PM
  5. How would you output an XML file with an Ole Attachment?
    By techneophyte in forum Programming
    Replies: 7
    Last Post: 09-09-2010, 09:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums