Пример #1
0
def processRmNest(xmlfile):
    #xmldoc = minidom.parse(xmlfile)
    xmldoc=process(xmlfile)
    #get root tags and child of root tags
    root = xmldoc.documentElement
    rootn=root.childNodes[1]
    root_begin,root_end=rmNest.getTags(root)    
    rootn_begin,rootn_end=rmNest.getTags(rootn)
    a=" ".join(rmNest.NestRM(rootn))
    xml_rmNest="<doc>" + a + "</doc>"
    root_rmNest=xml.dom.minidom.parseString(xml_rmNest)
    rootn_rmNest=root_rmNest.firstChild
    return rootn_rmNest,root_begin,root_end,rootn_begin,rootn_end
Пример #2
0
def processRmNest(xmlfile):
    #xmldoc = minidom.parse(xmlfile)
    xmldoc = process(xmlfile)
    #get root tags and child of root tags
    root = xmldoc.documentElement
    rootn = root.childNodes[1]
    root_begin, root_end = rmNest.getTags(root)
    rootn_begin, rootn_end = rmNest.getTags(rootn)
    a = " ".join(rmNest.NestRM(rootn))
    xml_rmNest = "<doc>" + a + "</doc>"
    root_rmNest = xml.dom.minidom.parseString(xml_rmNest)
    rootn_rmNest = root_rmNest.firstChild
    return rootn_rmNest, root_begin, root_end, rootn_begin, rootn_end
Пример #3
0
def print_node_NoSgton(root,d):
    """traverse the entire xml DOM and print out without nested inner element tags with same IDs"""
    if root.childNodes:
        
        for node in root.childNodes:
            singleton=False
            #node is a tag with attribute
            if node.nodeType == node.ELEMENT_NODE:
                begin_tag,end_tag=rmNest.getTags(node)
                key=node.attributes['ID'].value
                if d[key]==1:
                    singleton=True
                else:
                    print begin_tag
                
            #node is plain text
            text=node.nodeValue
            if text:
                print text.strip()

            print_node_NoSgton(node,d)
            if singleton==False:
                if node.nodeType == node.ELEMENT_NODE:
                    #cid=node.attributes['ID'].value
                    print end_tag
Пример #4
0
def print_node_NoSgton(root, d):
    """traverse the entire xml DOM and print out without nested inner element tags with same IDs"""
    if root.childNodes:

        for node in root.childNodes:
            singleton = False
            #node is a tag with attribute
            if node.nodeType == node.ELEMENT_NODE:
                begin_tag, end_tag = rmNest.getTags(node)
                key = node.attributes['ID'].value
                if d[key] == 1:
                    singleton = True
                else:
                    print begin_tag

            #node is plain text
            text = node.nodeValue
            if text:
                print text.strip()

            print_node_NoSgton(node, d)
            if singleton == False:
                if node.nodeType == node.ELEMENT_NODE:
                    #cid=node.attributes['ID'].value
                    print end_tag