我有一个结构如下所示的 xml 文件。
问题:如何选择/查询那些带有子元素的元素,其子元素的总和(数量)不等于其自身数量?
没有固定数量的子元素,甚至有没有子元素的元素,这些后面的元素不应该出现在选择中。
来自 json bubbletree 文件的文件结构:
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="JSON">
<xs:complexType>
<xs:sequence>
<xs:element ref="label"/>
<xs:element ref="amount"/>
<xs:element ref="color"/>
<xs:element maxOccurs="unbounded" ref="children"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="label" type="xs:string"/>
<xs:element name="amount" type="xs:integer"/>
<xs:element name="color" type="xs:string"/>
<xs:element name="children">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="amount"/>
<xs:element ref="children"/>
<xs:element ref="color"/>
<xs:element ref="label"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>'
来自气泡图 json 文件。
我在以下 xml 文件中寻找标签以“x”开头的元素(手动输入以澄清,在真实文件中不存在):
'<?xml version="1.0" encoding="UTF-8"?>
<JSON>
<label>total</label>
<amount>30</amount>
<children>
<label>x 1</label>
<amount>10</amount>
<children>
<label>1.1</label>
<amount>5</amount>
</children>
<children>
<label>1.2</label>
<amount>6</amount>
</children>
</children>
<children>
<label>2</label>
<amount>10</amount>
<children>
<label>2.1</label>
<amount>5</amount>
</children>
<children>
<label>x 2.2</label>
<amount>5</amount>
<children>
<label>2.2.1</label>
<amount>3</amount>
</children>
<children>
<label>2.2.2</label>
<amount>1</amount>
</children>
<children>
<label>2.2.3</label>
<amount>3</amount>
</children>
</children>
</children>
<children>
<label>x 3</label>
<amount>10</amount>
<children>
<label>3.1</label>
<amount>5</amount>
</children>
<children>
<label>3.2</label>
<amount>6</amount>
</children>
</children>
</JSON>'