我正在使用具有以下结构的xml文件。
<GroupType1>
并且<GroupType2>
需要单独处理。
无论哪种情况,我都想使用XPATH遍历<OperationEvent>
每个元素<OperationStage>
。
因此,对于每一个<GroupType1>
,我需要获取<OperationStage>
in的数量<OperationStageCollection>
,然后获取current中的<OperationEvent>
in的数量。<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>
的<OperationStageCollection>
,并且数量<OperationEvent>
在<OperationEventCollection>
当前的<OperationStage>
。
我尝试了各种表达式,例如:
i = xDOC.selectNodes("//OperationStage").length
但是,当然,这只是获取总数的<OperationStage>
整个<GroupCollection>
。我尝试过的其他表达式(如下)都返回零。如您所见,我只是在这里闲逛-暴露了我对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
获取单个<OperationStage>
in的数量,然后获取当前in的数量的正确语法是什么?<OperationStageCollection>
<GroupType1>
<OperationEvent>
<OperationEventCollection>
<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)
应该让你的号码<OperationStage>
S IN<OperationStageCollection>
单的<GroupType1>
和
//GroupType1/OperationStageCollection/OperationStage//OperationEventCollection/count(OperationEvent)
应该让您获得当前的<OperationEvent>
s的数量。<OperationEventCollection>
<OperationStage>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句