XPATH:如何获取第一个元素组的.length 和第一组中第二个元素组的.length?

XPATH: how get .length of 1st element group and .length of 2nd element group inside 1st group?

我正在处理 xml 具有以下结构的文件。

<GroupType1><GroupType2>需要分开处理

无论哪种情况,我都想使用 XPATH 遍历每个 <OperationStage> 中的 <OperationEvent> 元素。

因此,对于每个 <GroupType1>,我需要在 <OperationStageCollection> 中获取 <OperationStage> 的数量,然后在 <OperationEventCollection> 中获取 <OperationEvent> 的数量] 当前 <OperationStage>.

在伪代码中,处理将是:

    For i = 1 to number of <OperationStageCode> in current <OperationStage> of current <GroupType1>
        For j = 1 to number of <OperationEvent> in ith <OperationStage> in the current <GroupType1>
            process jth <OperationEvent> of ith <OperationStage>
        Next J
    Next i

然后我会为 <GroupType2>

做同样的事情

我一直在尝试获取 <OperationStageCollection> 中的 <OperationStage> 的数量,以及当前 <OperationStage><OperationEventCollection> 中的 <OperationEvent> 的数量].

我试过各种表达方式,例如:

i = xDOC.selectNodes("//OperationStage").length

当然那只是得到整个<GroupCollection><OperationStage>的总数。我试过的其他表达式(下面)都是 return 零。如您所见,我只是在这里胡说八道——暴露了我对 XPATH 遍历语法的不熟悉。

i = xDOC.selectNodes("/OperationStage").length
i = xDOC.selectNodes("OperationStageCollection//catmk:ProceedingStage").length
i = xDOC.selectNodes("OperationStageCollection/catmk:ProceedingStage").length
i = xDOC.selectNodes("/OperationStageCollection/catmk:ProceedingStage").length

获取单个 <GroupType1><OperationStageCollection><OperationStage> 的数量,然后获取 [=22] 中 <OperationEvent> 的数量的正确语法是什么=] 当前 <OperationStage>?

我查看了很多 XPATH 文档,但我没有找到任何关于我的情况的有用示例。如果您知道,也请指出此类文档。

这是 xml 结构:

<GroupCollection>
    <Groups>
        <GroupType1>
            <GroupType1_Identifier>1</GroupType1_Identifier>
            <OperationStageCollection>
                <OperationStage>
                     <OperationStageCode>3</OperationStageCode>
                        <OperationEventCollection>
                            <OperationEvent>
                                <OperationEventDate1>2018-12-16</OperationEventDate1>
                                <OperationEventCode>5</OperationEventCode>
                                <OperationEventDate2>2018-05-16</OperationEventDate2>
                            </OperationEvent>
                            ... more OperationEvents ...
                        </OperationEventCollection>
                </OperationStage>
                ... more OperationStages ...
            </OperationStageCollection>
        </GroupType1>
        ...moreGroupType1...
         <GroupType2>
            <GroupType2_Identifier>3</GroupType2_Identifier>
            <OperationStageCollection>
                <OperationStage>
                    <OperationStageCode>101</OperationStageCode>
                        <OperationEventCollection>
                            <OperationEvent>
                                <OperationEventCode>6</OperationEventCode>
                                <OperationEventDate2>2012-01-03</OperationEventDate2>
                            </OperationEvent>
                            ... more OperationEvents ...
                        </OperationEventCollection>
                </OperationStage>
                ... more OperationStages ...
            </OperationStageCollection>
        </GroupType2>
        ...moreGroupType2...
    </Groups>
</GroupCollection>

严格按照 xpath 表达式,我相信

//GroupType1/OperationStageCollection/count(OperationStage)

应该可以得到单个 <GroupType1>

<OperationStageCollection><OperationStage> 的数量
//GroupType1/OperationStageCollection/OperationStage//OperationEventCollection/count(OperationEvent)

应该得到当前 <OperationStage><OperationEventCollection><OperationEvent> 的数量。