2012-07-25 69 views
0

我有我的XML文件的路徑:的Javascript querySelector CDATA在XML文件中

<description> 
    <![CDATA[<p class="image"><img width="250" height="83" src="http://www.mydomain.com/picture/pic01.png" class="post-image" alt="Post 01 Image" title="The Demo Post" /></p>My Content 
    ]]> 
</description> 

如何選擇使用querySelector(JavaScript)的在CDATA的SRC屬性附加傷害標籤img的

謝謝!

回答

0
var description = xmldoc.getElementsByTagName("description")[0], 
    html = description.innerText || description.textContent, 
    root = document.createElement("div"), 
    imgsrc; 

root.innerHTML = html; 
imgsrc = root.querySelector("img").src; 
+0

哦!謝謝!它的工作:D – ImYuta 2012-07-25 08:40:20

+0

@ImYuta你應該[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)如果你的問題已經解決 – Esailija 2012-07-25 08:41:39