2011-07-25 55 views
2

下面是我的xml文檔,現在我的查詢是:/description/*/text(),我可以得到除<strong> lunch </strong>「午餐」不顯示的文字外的所有文字。xpath查詢問題

這可能是一個簡單的修復,但我只是無法弄清楚它的正確性。

<description> 
<![CDATA[ 
<p> 
    Envie is a brand new Bar Lounge that offers a modern-design space opening onto Wyndham Street, where on busy nights the crowd spills out onto the street... 
</p> 
<p> 
    If you are in for a <strong>lunch</strong>, the Twangoo voucher will offer you two delicious Lunches &ndash; perfect for that lunch meeting, a casual date or just a get together with friends in a relaxed and modern atmosphere. 
</p> ]]> 
</description> 
+0

你的XML包含'CDATA'?你需要在'CDATA'裏解析XML嗎? –

回答

3

嘗試

/description//text() 

現在你是爲了描述的所有子節點只選擇每個文本。

如果您改用//text();您正在爲當前節點(描述)的所有節點選擇每個文本。

+0

非常感謝您的幫助。 – kevin

+0

很高興。如果答案解決了您的問題,請將其標記爲已解決。它爲很多人節省了一些時間。 – CaBieberach

0

您的查詢/說明/ */text()選擇description元素的子元素的文本節點子元素。但description元素沒有元素子元素。除了CDATA正在告訴解析器不要將<p>...</p>內容視爲標記,而是將其作爲純文本處理外,它應該具有。我不知道爲什麼XML將這些東西包裝在CDATA中,但是它使得處理它或查詢它變得更加困難。