Windows命令在xml文件的父标记中查找子标记的组合

时间:2018-10-30 10:12:05

标签: xml string windows command findstr

下面是我的示例XML

<parent1>
<child1>test1</child1>
<child2>test2</child2>
<child3>test3</child3>
</parent1>

<parent2>
<child1>test1</child1>
<child2>test2</child2>
<child3>test3</child3>
</parent2>

<parent3>
<child1>test1</child1>
<child2>test2</child2>
<child3>test3</child3>
</parent3>

现在我想找到以下组合的发生次数

 <child1>test1</child1>
 <child3>test3</child3>

我尝试使用以下命令

findstr /R /c:"<child1>test1</child1>.*<child3>test3</child3>*" test.xml

,但是它希望child1和child3都在一行中。

因为它在不同的行中,所以没有计数。

有人可以帮我找出执行此要求的窗口命令吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

您必须搜索<child1>test1</child1><child3>test3</child3>

@echo off

findstr /n /r /c:"<child1>test1</child1>" /c:"<child3>test3</child3>" data4.xml | find /c ":"

使用/C中的参数find,您可以获得结果数。

相关问题