Я извлек содержимое RSS-канала с помощью JS, однако узел «Описание» содержит CDATA, и я хочу его разделить.
Например, для каждого узла описания в элементе я хотел бы извлечь только содержимое от <b>Brief Description:</b>
до первого </div>
.
Это возможно? Ниже приведен пример того, что у меня есть на данный момент, а также xml из RSS-канала ниже.
Надеюсь, кто-то может помочь :)
Пример сценария
<SCRIPT type=text/javascript>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","help/Sandbox/XML%20Playground/_layouts/listfeed.aspx?List=%7B1D503F3E%2D4BFF%2D4248%2D848D%2DE12B5B67DAEC%7D",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
function media(){
description=xmlDoc.getElementsByTagName('description');
a=2;
b=1;
for (i=0;i<18;i++)
{
document.write('<p>' + description[b].childNodes[0].nodeValue + '</p>');
b++;
a++;
};
};
</SCRIPT>
RSS XML FEED
<?xml version="1.0" encoding="UTF-8"?>
<!--RSS generated by Windows SharePoint Services V3 RSS Generator on 8/03/2011 10:51:51 AM-->
<?xml-stylesheet type="text/xsl" href="/help/Sandbox/XML Playground/_layouts/RssXslt.aspx?List=1d503f3e-4bff-4248-848d-e12b5b67daec" version="1.0"?>
<rss version="2.0">
<channel>
<title>XML Playground: Media News</title>
<link>/help/Sandbox/XML Playground/Lists/Media News/AllItems.aspx</link>
<description>RSS feed for the Media News list.</description>
<lastBuildDate>Mon, 07 Mar 2011 23:51:51 GMT</lastBuildDate>
<generator>Windows SharePoint Services V3 RSS Generator</generator>
<ttl>60</ttl>
<image>
<title>XML Playground: Media News</title>
<url>/help/Sandbox/XML Playground/_layouts/images/homepage.gif</url>
<link>help/Sandbox/XML Playground/Lists/Media News/AllItems.aspx</link>
</image>
<item>
<title>new Item</title>
<link>/help/Sandbox/XML Playground/Lists/Media News/DispForm.aspx?ID=2</link>
<description><![CDATA[<div><b>Brief Description:</b> <div>bla blah blah ablkahgohoihjsdofsdf dfhfgh</div></div>
<div><b>Thumbnail:</b> <a href="/news/PublishingImages/MySchool_rollup-120-x-120_new-040311.gif">test image</a></div>
]]></description>
<author>WALKER,Andrew</author>
<pubDate>Mon, 07 Mar 2011 05:43:19 GMT</pubDate>
<guid isPermaLink="true">http:/help/Sandbox/XML Playground/Lists/Media News/DispForm.aspx?ID=2</guid>
</item>
<item>
<title>My School 2.0 launched</title>
<link>http://dnet.hosts.network/help/Sandbox/XML Playground/Lists/Media News/DispForm.aspx?ID=1</link>
<description><![CDATA[<div><b>Brief Description:</b> <div>On Friday 4 March 2011 the Minister for School Education, Peter Garrett, launched My School 2.0.</div></div>
<div><b>Thumbnail:</b> <a href="http://dnet.hosts.network/news/PublishingImages/MySchool_rollup-120-x-120_new-040311.gif"></a></div>
<div><b>Release Date:</b> 16/03/2011</div>
]]></description>
<pubDate>Fri, 04 Mar 2011 04:34:11 GMT</pubDate>
<guid isPermaLink="true">/help/Sandbox/XML Playground/Lists/Media News/DispForm.aspx?ID=1</guid>
</item>
</channel>
</rss>