我正在使用具有以下结构的xml文件。
<GroupType1>
和<GroupType2>
需要分别处理。
无论哪种情况,我都希望使用XPATH遍历每个<OperationEvent>
中的<OperationStage>
元素。
因此,对于每个<GroupType1>
,我需要获取<OperationStage>
中<OperationStageCollection>
的数量,然后获取<OperationEvent>
中<OperationEventCollection>
的数量。当前的<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>
我一直想获取当前<OperationStage>
的{{1}}中<OperationStageCollection>
的数目和<OperationEvent>
中<OperationEventCollection>
的数目。
我尝试了各种表达式,例如:
<OperationStage>
但是,当然,这只是获得整个i = xDOC.selectNodes("//OperationStage").length
中<OperationStage>
的总数。我尝试过的其他表达式(如下)都返回零。如您所见,我只是在这里闲逛-暴露了我对XPATH遍历语法的不熟悉。
<GroupCollection>
从单个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
的{{1}}中获得<OperationStage>
的数目,然后在<OperationStageCollection>
中获得<GroupType1>
的数目的正确语法是什么当前<OperationEvent>
中的哪个?
我看了很多XPATH文档,但是在我所处的情况下,我没有发现任何有用的示例。如果您知道的话,也请给我指出这些文件。
这是xml结构:
<OperationEventCollection>
答案 0 :(得分:0)
我相信严格按照xpath表达式
//GroupType1/OperationStageCollection/count(OperationStage)
应该为您获取单个<OperationStage>
和
<OperationStageCollection>
中<GroupType1>
个的数量
//GroupType1/OperationStageCollection/OperationStage//OperationEventCollection/count(OperationEvent)
应该为您获取当前<OperationEvent>
的{{1}}中<OperationEventCollection>
个的数量。