XML to Microsoft Access — avoid losing keys












1















I want to import an XML document into Microsoft Access 2010. Here is a sample from the XML:



<ROWSET>   
<BIOG>
<BIOG_NBR> 10021616 </BIOG_NBR>
<FIRST_NAME> Marvin </FIRST_NAME>
<LAST_NAME> Rumple </LAST_NAME>
<ADDRESS_LIST>
<ADDRESS_TYP>
<ORG1> UNICEF </ORG1>
<ADDRESS_TYPE>Work </ADDRESS_TYPE>
<LINE_2> 23322 Bovine Blvd </LINE_2>
<US_ZIP> 770303411 </US_ZIP>
<CONTACT_LIST/>
</ADDRESS_TYP>
<ADDRESS_TYP>
<ORG1> MENSA </ORG1>
<ADDRESS_TYPE>Leisure </ADDRESS_TYPE>
<LINE_2> 421 Porcine Lane </LINE_2>
<US_ZIP> 770303411 </US_ZIP>
<CONTACT_LIST/>
</ADDRESS_TYP>
</ADDRESS_LIST>
</BIOG>


This is a well-formed XML document. It has a DTD definition document, but I remove the declaration because the Access import won't accept it. <ROWSET> is the root element. My example is simplified -- eight tables are represented in the schema.



When I import this, I get two tables, BIOG and ADDRESS_TYP. But ADDRESS_TYP doesn't show the foreign key BIOG_NBR.



enter image description here



How can I bring that in? Some ways that occur to me:




  1. Use a text editor with regular expressions to insert <BIOG_NBR>____</BIOG_NBR> immediately after each instance of <ADDRESS_TYP>. This is inelegant, and because the file is 200Mb it may be impractical.

  2. Use another XML parser to export all data to csv files. This would be my first option but I am under workplace limitations that exclude it.

  3. Use some kind of transform like XSD. I've used this approach to render to HTML, but does it apply to this task? (And then, don't I still need an XML parser? Obviously yes...)

  4. Use the Microsoft XML Library in VBA. (Does this apply?)


In a nutshell: Should I reach for a native XML tool, as in option #3? Is there another approach I'm missing?










share|improve this question





























    1















    I want to import an XML document into Microsoft Access 2010. Here is a sample from the XML:



    <ROWSET>   
    <BIOG>
    <BIOG_NBR> 10021616 </BIOG_NBR>
    <FIRST_NAME> Marvin </FIRST_NAME>
    <LAST_NAME> Rumple </LAST_NAME>
    <ADDRESS_LIST>
    <ADDRESS_TYP>
    <ORG1> UNICEF </ORG1>
    <ADDRESS_TYPE>Work </ADDRESS_TYPE>
    <LINE_2> 23322 Bovine Blvd </LINE_2>
    <US_ZIP> 770303411 </US_ZIP>
    <CONTACT_LIST/>
    </ADDRESS_TYP>
    <ADDRESS_TYP>
    <ORG1> MENSA </ORG1>
    <ADDRESS_TYPE>Leisure </ADDRESS_TYPE>
    <LINE_2> 421 Porcine Lane </LINE_2>
    <US_ZIP> 770303411 </US_ZIP>
    <CONTACT_LIST/>
    </ADDRESS_TYP>
    </ADDRESS_LIST>
    </BIOG>


    This is a well-formed XML document. It has a DTD definition document, but I remove the declaration because the Access import won't accept it. <ROWSET> is the root element. My example is simplified -- eight tables are represented in the schema.



    When I import this, I get two tables, BIOG and ADDRESS_TYP. But ADDRESS_TYP doesn't show the foreign key BIOG_NBR.



    enter image description here



    How can I bring that in? Some ways that occur to me:




    1. Use a text editor with regular expressions to insert <BIOG_NBR>____</BIOG_NBR> immediately after each instance of <ADDRESS_TYP>. This is inelegant, and because the file is 200Mb it may be impractical.

    2. Use another XML parser to export all data to csv files. This would be my first option but I am under workplace limitations that exclude it.

    3. Use some kind of transform like XSD. I've used this approach to render to HTML, but does it apply to this task? (And then, don't I still need an XML parser? Obviously yes...)

    4. Use the Microsoft XML Library in VBA. (Does this apply?)


    In a nutshell: Should I reach for a native XML tool, as in option #3? Is there another approach I'm missing?










    share|improve this question



























      1












      1








      1








      I want to import an XML document into Microsoft Access 2010. Here is a sample from the XML:



      <ROWSET>   
      <BIOG>
      <BIOG_NBR> 10021616 </BIOG_NBR>
      <FIRST_NAME> Marvin </FIRST_NAME>
      <LAST_NAME> Rumple </LAST_NAME>
      <ADDRESS_LIST>
      <ADDRESS_TYP>
      <ORG1> UNICEF </ORG1>
      <ADDRESS_TYPE>Work </ADDRESS_TYPE>
      <LINE_2> 23322 Bovine Blvd </LINE_2>
      <US_ZIP> 770303411 </US_ZIP>
      <CONTACT_LIST/>
      </ADDRESS_TYP>
      <ADDRESS_TYP>
      <ORG1> MENSA </ORG1>
      <ADDRESS_TYPE>Leisure </ADDRESS_TYPE>
      <LINE_2> 421 Porcine Lane </LINE_2>
      <US_ZIP> 770303411 </US_ZIP>
      <CONTACT_LIST/>
      </ADDRESS_TYP>
      </ADDRESS_LIST>
      </BIOG>


      This is a well-formed XML document. It has a DTD definition document, but I remove the declaration because the Access import won't accept it. <ROWSET> is the root element. My example is simplified -- eight tables are represented in the schema.



      When I import this, I get two tables, BIOG and ADDRESS_TYP. But ADDRESS_TYP doesn't show the foreign key BIOG_NBR.



      enter image description here



      How can I bring that in? Some ways that occur to me:




      1. Use a text editor with regular expressions to insert <BIOG_NBR>____</BIOG_NBR> immediately after each instance of <ADDRESS_TYP>. This is inelegant, and because the file is 200Mb it may be impractical.

      2. Use another XML parser to export all data to csv files. This would be my first option but I am under workplace limitations that exclude it.

      3. Use some kind of transform like XSD. I've used this approach to render to HTML, but does it apply to this task? (And then, don't I still need an XML parser? Obviously yes...)

      4. Use the Microsoft XML Library in VBA. (Does this apply?)


      In a nutshell: Should I reach for a native XML tool, as in option #3? Is there another approach I'm missing?










      share|improve this question
















      I want to import an XML document into Microsoft Access 2010. Here is a sample from the XML:



      <ROWSET>   
      <BIOG>
      <BIOG_NBR> 10021616 </BIOG_NBR>
      <FIRST_NAME> Marvin </FIRST_NAME>
      <LAST_NAME> Rumple </LAST_NAME>
      <ADDRESS_LIST>
      <ADDRESS_TYP>
      <ORG1> UNICEF </ORG1>
      <ADDRESS_TYPE>Work </ADDRESS_TYPE>
      <LINE_2> 23322 Bovine Blvd </LINE_2>
      <US_ZIP> 770303411 </US_ZIP>
      <CONTACT_LIST/>
      </ADDRESS_TYP>
      <ADDRESS_TYP>
      <ORG1> MENSA </ORG1>
      <ADDRESS_TYPE>Leisure </ADDRESS_TYPE>
      <LINE_2> 421 Porcine Lane </LINE_2>
      <US_ZIP> 770303411 </US_ZIP>
      <CONTACT_LIST/>
      </ADDRESS_TYP>
      </ADDRESS_LIST>
      </BIOG>


      This is a well-formed XML document. It has a DTD definition document, but I remove the declaration because the Access import won't accept it. <ROWSET> is the root element. My example is simplified -- eight tables are represented in the schema.



      When I import this, I get two tables, BIOG and ADDRESS_TYP. But ADDRESS_TYP doesn't show the foreign key BIOG_NBR.



      enter image description here



      How can I bring that in? Some ways that occur to me:




      1. Use a text editor with regular expressions to insert <BIOG_NBR>____</BIOG_NBR> immediately after each instance of <ADDRESS_TYP>. This is inelegant, and because the file is 200Mb it may be impractical.

      2. Use another XML parser to export all data to csv files. This would be my first option but I am under workplace limitations that exclude it.

      3. Use some kind of transform like XSD. I've used this approach to render to HTML, but does it apply to this task? (And then, don't I still need an XML parser? Obviously yes...)

      4. Use the Microsoft XML Library in VBA. (Does this apply?)


      In a nutshell: Should I reach for a native XML tool, as in option #3? Is there another approach I'm missing?







      microsoft-access xml






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 23 '17 at 12:41









      Community

      1




      1










      asked Nov 20 '14 at 20:16









      SmandoliSmandoli

      104214




      104214






















          1 Answer
          1






          active

          oldest

          votes


















          0














          It's too easy.



          STEP 1 -- make an import of the data using the standard Access "Import XML" option. Structure only.



          STEP 2 -- Go to each table and add a field that will take the missing key.



          STEP 3 -- Use VBA. Add the Microsoft XML, v6.0 library. Even this spare bit of code tells me it will be simple to write the key to each table as needed.



          Dim oDoc As MSXML2.DOMDocument
          Dim fSuccess As Boolean
          Dim oRoot As MSXML2.IXMLDOMNode
          Dim oSoftkey As MSXML2.IXMLDOMNode
          Dim oAttributes As MSXML2.IXMLDOMNode

          Set oDoc = New MSXML2.DOMDocument

          oDoc.async = False
          oDoc.validateOnParse = False

          fSuccess = oDoc.Load(strPath & "specimen.xml")

          If Not fSuccess Then Exit Sub

          ' Get the root of the XML tree.
          Set oRoot = oDoc.documentElement
          For Each oSoftkey In oRoot.ChildNodes

          For Each oAttributes In oSoftkey.ChildNodes

          Debug.Print oAttributes.Text
          Next
          Next oSoftkey





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f842873%2fxml-to-microsoft-access-avoid-losing-keys%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It's too easy.



            STEP 1 -- make an import of the data using the standard Access "Import XML" option. Structure only.



            STEP 2 -- Go to each table and add a field that will take the missing key.



            STEP 3 -- Use VBA. Add the Microsoft XML, v6.0 library. Even this spare bit of code tells me it will be simple to write the key to each table as needed.



            Dim oDoc As MSXML2.DOMDocument
            Dim fSuccess As Boolean
            Dim oRoot As MSXML2.IXMLDOMNode
            Dim oSoftkey As MSXML2.IXMLDOMNode
            Dim oAttributes As MSXML2.IXMLDOMNode

            Set oDoc = New MSXML2.DOMDocument

            oDoc.async = False
            oDoc.validateOnParse = False

            fSuccess = oDoc.Load(strPath & "specimen.xml")

            If Not fSuccess Then Exit Sub

            ' Get the root of the XML tree.
            Set oRoot = oDoc.documentElement
            For Each oSoftkey In oRoot.ChildNodes

            For Each oAttributes In oSoftkey.ChildNodes

            Debug.Print oAttributes.Text
            Next
            Next oSoftkey





            share|improve this answer




























              0














              It's too easy.



              STEP 1 -- make an import of the data using the standard Access "Import XML" option. Structure only.



              STEP 2 -- Go to each table and add a field that will take the missing key.



              STEP 3 -- Use VBA. Add the Microsoft XML, v6.0 library. Even this spare bit of code tells me it will be simple to write the key to each table as needed.



              Dim oDoc As MSXML2.DOMDocument
              Dim fSuccess As Boolean
              Dim oRoot As MSXML2.IXMLDOMNode
              Dim oSoftkey As MSXML2.IXMLDOMNode
              Dim oAttributes As MSXML2.IXMLDOMNode

              Set oDoc = New MSXML2.DOMDocument

              oDoc.async = False
              oDoc.validateOnParse = False

              fSuccess = oDoc.Load(strPath & "specimen.xml")

              If Not fSuccess Then Exit Sub

              ' Get the root of the XML tree.
              Set oRoot = oDoc.documentElement
              For Each oSoftkey In oRoot.ChildNodes

              For Each oAttributes In oSoftkey.ChildNodes

              Debug.Print oAttributes.Text
              Next
              Next oSoftkey





              share|improve this answer


























                0












                0








                0







                It's too easy.



                STEP 1 -- make an import of the data using the standard Access "Import XML" option. Structure only.



                STEP 2 -- Go to each table and add a field that will take the missing key.



                STEP 3 -- Use VBA. Add the Microsoft XML, v6.0 library. Even this spare bit of code tells me it will be simple to write the key to each table as needed.



                Dim oDoc As MSXML2.DOMDocument
                Dim fSuccess As Boolean
                Dim oRoot As MSXML2.IXMLDOMNode
                Dim oSoftkey As MSXML2.IXMLDOMNode
                Dim oAttributes As MSXML2.IXMLDOMNode

                Set oDoc = New MSXML2.DOMDocument

                oDoc.async = False
                oDoc.validateOnParse = False

                fSuccess = oDoc.Load(strPath & "specimen.xml")

                If Not fSuccess Then Exit Sub

                ' Get the root of the XML tree.
                Set oRoot = oDoc.documentElement
                For Each oSoftkey In oRoot.ChildNodes

                For Each oAttributes In oSoftkey.ChildNodes

                Debug.Print oAttributes.Text
                Next
                Next oSoftkey





                share|improve this answer













                It's too easy.



                STEP 1 -- make an import of the data using the standard Access "Import XML" option. Structure only.



                STEP 2 -- Go to each table and add a field that will take the missing key.



                STEP 3 -- Use VBA. Add the Microsoft XML, v6.0 library. Even this spare bit of code tells me it will be simple to write the key to each table as needed.



                Dim oDoc As MSXML2.DOMDocument
                Dim fSuccess As Boolean
                Dim oRoot As MSXML2.IXMLDOMNode
                Dim oSoftkey As MSXML2.IXMLDOMNode
                Dim oAttributes As MSXML2.IXMLDOMNode

                Set oDoc = New MSXML2.DOMDocument

                oDoc.async = False
                oDoc.validateOnParse = False

                fSuccess = oDoc.Load(strPath & "specimen.xml")

                If Not fSuccess Then Exit Sub

                ' Get the root of the XML tree.
                Set oRoot = oDoc.documentElement
                For Each oSoftkey In oRoot.ChildNodes

                For Each oAttributes In oSoftkey.ChildNodes

                Debug.Print oAttributes.Text
                Next
                Next oSoftkey






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '14 at 20:52









                SmandoliSmandoli

                104214




                104214






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f842873%2fxml-to-microsoft-access-avoid-losing-keys%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Plaza Victoria

                    Brian Clough

                    Cáceres