Extract CDATA from RSS XML using Javascript?

CDATA section content is just text, so you can't parse its contents further using the DOM. You can either use DOMParser() to reconstruct the string contents of the CDATA section back into XML and use DOM methods from there, or else use regular expressions To use the latter approach, change your document.write() line to this: Slice off 5 characters to get rid of the parent and use \s\S to mean // any character including newlines up until the first closing div tag document. Write('' + descriptionb.

ChildNodes0.nodeValue. Slice(5). Match(/\s\S*?

/) + '') To use the former approach, which is less than ideal in this case but could be helpful in other situations, you could do this inside the for loop: var cdataContent = new DOMParser(). ParseFromString(''+descriptionb. ChildNodes0.

NodeValue+'', 'text/xml'). DocumentElement; document.body. AppendChild(cdataContent.

FirstChild) but being sure to only invoke media() after the DOM content has loaded And maybe you have some good reason for it, but based on the code you supplied, it'd be a lot simpler just to do this: for (i=1; i.

CDATA section content is just text, so you can't parse its contents further using the DOM. You can either use DOMParser() to reconstruct the string contents of the CDATA section back into XML and use DOM methods from there, or else use regular expressions. To use the latter approach, change your document.write() line to this: // Slice off 5 characters to get rid of the parent and use \s\S to mean // any character including newlines up until the first closing div tag document.

Write('' + descriptionb. ChildNodes0.nodeValue. Slice(5).

Match(/\s\S*? /) + ''); To use the former approach, which is less than ideal in this case but could be helpful in other situations, you could do this inside the for loop: var cdataContent = new DOMParser(). ParseFromString(''+descriptionb.

ChildNodes0. NodeValue+'', 'text/xml'). DocumentElement; document.body.

AppendChild(cdataContent. FirstChild); ...but being sure to only invoke media() after the DOM content has loaded. And maybe you have some good reason for it, but based on the code you supplied, it'd be a lot simpler just to do this: for (i=1; iLength; i++) { ...and forget about a and be (i.e.

, change be to i) And one tip: if you construct the RSS yourself, note that you won't be able to use CDATA sections nested within CDATA sections.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions