How to import XML with nested nodes (parent/child relationships) into Access?

前端 未结 1 1049
别那么骄傲
别那么骄傲 2020-11-30 13:57

I\'m trying to import an XML file into Access but it creates 3 unrelated tables. That is, the child records are imported into the child table, but there is no way of knowing

1条回答
  •  情深已故
    2020-11-30 14:35

    What you need to do is transform your XML data into a format that works better with Access. Specifically, you need to insert the parent key value (assuming that it is C_NOT in this case) into each child node.

    The following XSLT file will do that for you

    
        
        
    
        
            
                
            
        
    
        
            
                
            
        
    
        
            
        
    
        
            
                
                
            
        
    
    
    

    That will transform your XML from this ...

    
        8404180
        Abalos Nuevo
        Francisco José
        
            
                23
                0888
                1984-12-01
                1986-09-19
            
            
                14
                0569
                1990-09-17
                1995-03-15
            
            
                21
                0412
                1995-03-30
                
            
        
    
    

    ... into this:

    
    
        
            8404180
            Abalos Nuevo
            Francisco José
            
                8404180
                23
                0888
                1984-12-01
                1986-09-19
            
            
                8404180
                14
                0569
                1990-09-17
                1995-03-15
            
            
                8404180
                21
                0412
                1995-03-30
                
            
        
    
    

    ... in the background while Access is importing it.

    Save that XSLT file to your hard drive (I called mine "transformio.xslt"), then start the Access XML import process. Once you've selected your XML file to import, click the "Transform" button ...

    ImportXmlDialog.png

    ... add your newly-created XSLT file to the list and select it ...

    ImportTransforms.png

    When you click "OK" and return to the "Import XML" dialog, you can expand the tree view to see that you now have C_NOT values in both tables.

    ImportXml2.png

    When the import is complete you will still have two tables, but now you can JOIN them on C_NOT to get a "flat" view of the data:

    QueryDesign.png

    which gives us

    QuerySheet.png

    0 讨论(0)
提交回复
热议问题