Oracle數據庫10g企業版發行10.2.0.5 - 64biXPATH祖先或自身
我試圖從元件輸出hierarhy,我發現,使用祖先或自身根,但不工作的時候:剛剛打印的所有元素(
嗯,我有什麼:
1)像這樣的XML文件。
<Root>
<Element1 id="UniqueId1">
<SubElement1 id="UniqueId2"/>
<SubElement2 id="UniqueId3">
<LeafElement1 id="UniqueId4"/>
<LeafElement1 id="UniqueId5"/>
</SubElement2>
</Element1>
<Element2 id="UniqueId6" AttributeToCheck="true">
<SubElement1 id="UniqueId7">
<LeafElement1 id="UniqueId8"/>
<LeafElement1 id="UniqueId9"/>
</SubElement1>
</Element2>
</Root>
2)我的XPath字符串:
//*[@id and contains(@id, "UniqueId8")]/ancestor-or-self::*
3)我要得到這樣的結果(從找到的元素根):
<Root>
<Element2 id="UniqueId6" AttributeToCheck="true">
<SubElement1 id="UniqueId7">
<LeafElement1 id="UniqueId8"/>
</SubElement1>
</Element2>
</Root>
順便說一句,//[@id和包含(@id,「UniqueId8」)]/ancestor-or-self ::/@ id正常。
有誰知道如何解決這個問題,或者只是使用其他操作而不是祖先或自己?
UPDATE:
我只是執行此:
DECLARE
v_xml XMLTYPE;
BEGIN
SELECT xmltype('<Root>
<Element1 id="UniqueId1">
<SubElement1 id="UniqueId2"/> <SubElement2 id="UniqueId3">
<LeafElement1 id="UniqueId4"/>
<LeafElement1 id="UniqueId5"/>
</SubElement2>
</Element1>
<Element2 id="UniqueId6" AttributeToCheck="true">
<SubElement1 id="UniqueId7">
<LeafElement1 id="UniqueId8"/>
<LeafElement1 id="UniqueId9"/>
</SubElement1>
</Element2>
</Root>')
into v_xml
from dual;
select extract(v_xml, '//*[@id="UniqueId9"]/ancestor-or-self::*')
into v_xml
from dual;
dbms_output.put_line(v_xml.getStringVal());
END;
但作爲一個結果,我得到了一些奇怪的事情:
<Root>
<Element1 id="UniqueId1">
<SubElement1 id="UniqueId2"/>
<SubElement2 id="UniqueId3">
<LeafElement1 id="UniqueId4"/>
<LeafElement1 id="UniqueId5"/>
</SubElement2>
</Element1>
<Element2 id="UniqueId6" AttributeToCheck="true">
<SubElement1 id="UniqueId7">
<LeafElement1 id="UniqueId8"/>
<LeafElement1 id="UniqueId9"/>
</SubElement1></Element2>
</Root>
<Element2 id="UniqueId6" AttributeToCheck="true">
<SubElement1 id="UniqueId7">
<LeafElement1 id="UniqueId8"/>
<LeafElement1 id="UniqueId9"/>
</SubElement1>
</Element2>
<SubElement1 id="UniqueId7">
<LeafElement1 id="UniqueId8"/>
<LeafElement1 id="UniqueId9"/>
</SubElement1>
<LeafElement1 id="UniqueId9"/>
我不想改變結構,我只是需要獲得像這樣的結果http://chris.photobooks.com/xml/default.htm?state=9D – user485553
那麼即使該頁面顯示了完整的樹,只有它突出顯示了某些節點。也許DazzaL的回答比我引用XQuery或XSLT更有幫助,但我不熟悉Oracle中的XML數據類型支持。 –
我想你也會對XQuery感興趣。我有XQuery解決方案https://forums.oracle.com/forums/thread.jspa?threadID=2463473&tstart=0但是我仍然在尋找XPath解決方案! – user485553