0

How can I read data present in a large XML file using SAX parser?. I want to transfer the data from XML into tables created in MS Access.

Please help.
Regards,
Dinil

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by tzushky
0

Hi,

first of all, Python has modules that allow you to parse. I haven't used SAX, but I've used DOM. Here's the reference for all Structured Markup Processing Tools in Python:
http://docs.python.org/lib/markup.html

Then, if your know the structure of your XML, the tags, the attributes, etc, it will be relatively easy to create the functions which parse the tags inward and extract the value of the attributes that interest you, which you can afterward send wherever you want:

Example:

def GetXmlList(XmlList):
    
    Dom = xml.dom.minidom.parse(XmlList)
    Root = Dom.getElementsByTagName(Root_Name)[0]

    # Scan base list
    Level1= dict()
    Node = GetChild(Root, LEVEL1_nameTag)
    for Child in Node.childNodes:
        if Child.nodeType == Child.ELEMENT_NODE:
            Name = str(Child.nodeName)
            if not Name in Level1:
                Level1[Name] = Child

    # Scan file list
    Level2 = dict()
    Node = GetChild(Root, LEVEL2_nameTag)
    for Child in Node.childNodes:
        if Child.nodeType == Child.ELEMENT_NODE:
            Name = GetAttribut(Child, LEVEL2_nameAttr)
            if Name in ...

            #do whatever you want...

    return Level1, Level2...

Did I enlighten a bit?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.