【发布时间】:2014-07-21 16:15:58
【问题描述】:
以下 xml 是我的 xml 文件的一部分。我需要获得没有维修的汽车的制造商名称。举个小例子,我尝试过以下操作,但它可以工作,但是当汽车数量增加时,它不会返回正确的输出:
@xpath /*/descendant::maintenances[not(maintenance)]/preceding::manufacturer/text()
顺便说一句,我也试过这些:
@xpath /descendant::maintenances[not(*)][not(normalize-space())]/preceding::manufacturer/text()
@xpath /descendant::maintenances[not(maintenance)]/preceding::manufacturer/text()
@xpath /descendant::maintenances[not(maintenance())]/preceding::manufacturer/text()
小例子:
<vehicles>
<car rego="XYZ007">
<manufacturer>Toyota2</manufacturer>
<model>Camry</model>
<capacity>5</capacity>
<maintenances/>
</car>
<car rego="ABC123">
<manufacturer>Toyota</manufacturer>
<model>Corolla</model>
<capacity>4</capacity>
<maintenances>
<maintenance enum="m0045">
<mdate>20-JAN-2012</mdate>
<parts>
<part>air filter</part>
</parts>
<description>Replaced air filter</description>
</maintenance>
</maintenances>
</car>
</vehicles>
输出: Toyota2
大例子:
<vehicles>
<bus rego="PKR856">
<manufacturer>MAN</manufacturer>
<capacity>52</capacity>
<maintenances>
<maintenance enum="m1234">
<mdate>12-MAR-2009</mdate>
<parts>
<part>tire</part>
</parts>
<description>Changed tires</description>
</maintenance>
</maintenances>
</bus>
<bus rego="UUQ007">
<manufacturer>Volvo</manufacturer>
<capacity>60</capacity>
<maintenances>
<maintenance mnum="m1234">
<mdate>10-JAN-2001</mdate>
<parts>
<part>air filter</part>
<part>oil filter</part>
<part>engine oil</part>
</parts>
<description>Replaced engine oil, oil filter, and air filter</description>
</maintenance>
</maintenances>
</bus>
<bus rego="XYZ987">
<manufacturer>Volvo</manufacturer>
<capacity>60</capacity>
</bus>
<truck>
<manufacturer>Volvo</manufacturer>
<capacity>6000</capacity>
<maintenances>
<maintenance enum="m1234">
<mdate>10-JAN-2011</mdate>
<parts>
<part>air filter</part>
</parts>
<description>Replaced air filter</description>
</maintenance>
<maintenance enum="m1234">
<mdate>13-MAY-2014</mdate>
<parts>
<part>fuel pump</part>
</parts>
<description>Replaced fuel pump</description>
</maintenance>
</maintenances>
</truck>
<truck rego="ZZZ777">
<manufacturer>Kenworth</manufacturer>
<capacity>5000</capacity>
<horsepower>38</horsepower>
<maintenances/>
</truck>
<car rego="XYZ007">
<manufacturer>Toyota</manufacturer>
<model>Camry</model>
<capacity>5</capacity>
<maintenances/>
</car>
<car rego="ABC123">
<manufacturer>Toyota</manufacturer>
<model>Corolla</model>
<capacity>4</capacity>
<maintenances>
<maintenance enum="m0045">
<mdate>20-JAN-2012</mdate>
<parts>
<part>air filter</part>
</parts>
<description>Replaced air filter</description>
</maintenance>
</maintenances>
</car>
<limousine rego="VVV001">
<manufacturer>Maserati</manufacturer>
<capacity>2</capacity>
</limousine>
<limousine rego="PKR856">
<manufacturer>Rolls Royce</manufacturer>
<capacity>4</capacity>
<maintenances>
<maintenance enum="m0001">
<mdate>12-JUN-2006</mdate>
<parts>
<part>ash tray</part>
</parts>
<description>Replaced golden ash tray</description>
</maintenance>
</maintenances>
</limousine>
</vehicles>
输出:所有汽车
【问题讨论】:
-
我不是 xpath 大师,但你试过这个:stackoverflow.com/questions/862239/… 吗?
-
@uraf 是的,我看到了。如您所见,我的其他语句没有 /*。
标签: sql xml oracle xpath oracle11g