Python中XML文件值的比较

2024-06-10 00:31:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我的UML图是这样的:

rootNode
   |
Book (attribute:name)
   |
Table (attribute: Name)
   |
TableEntry(attribute: Field, Value)

当我使用此代码时:

for Book in rootNode.getBooks():
    print Book.getName()
    for Table in Book.getTables():
        print Table.getName()
        for TableEntry in Table.getTableEntrys():
            print TableEntry.getField(), TableEntry.getValue()

输出如下:

Document
T1
F1  V1
F2  V2
F3  V3
F4  V4
F5  V5
F6  V6
T2
F1 V1
F2 V2
F3  V3
F4  V4
F5  V5
F6  V6
Document
T2
F2 V2
F3  V3
F4  V4
F5  V5
F6  V6

我想比较每个字段和值的字段和值ex-F1和文档中的值V1(第一个)和文档中的F1 V1(第二个)。 我有相同的书名为'文件'。 我还想在这两个文件中找到丢失的字段或附加字段,比如在T2中,我的F1和V1丢失了。你知道吗


Tags: infortableattributev3v2v4f2