简体   繁体   中英

Javascript querySelector CDATA in xml file

I have this path of my xml file:

<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>

How can i select the src atribute of tag img in CDATA using querySelector (Javascript).

Thanks!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM