Hi i want to parse xml/rss from a live url like http://rss.news.yahoo.com/rss/entertainment using pure Java Script(not jquery). I have googled a lot. Nothing worked for me. can any one help with a working piece of code.
Hi i want to parse xml/rss from a live url like http://rss.news.yahoo.com/rss/entertainment using pure
Share
(You cannot have googled a lot.) Once you have worked around the Same Origin Policy, and if the resource is served with an XML MIME type (which it is in this case,
text/xml), you can do the following:(See also AJAX, and the XMLHttpRequest Level 2 specification [Working Draft] for other event-handler properties.)
In essence: No parsing necessary. If you then want to access the XML data, use the standard DOM Level 2+ Core or DOM Level 3 XPath methods, e.g.
(See also JSX:xpath.js for a convenient, namespace-aware DOM 3 XPath wrapper that does not use jQuery.)
However, if for some (wrong) reason the MIME type is not an XML MIME type, or if it is not recognized by the DOM implementation as such, you can use one of the parsers built into recent browsers to parse the
responseTextproperty value. See pradeek’s answer for a solution that works in IE/MSXML. The following should work everywhere else:Proceed as described above.
Use feature tests at runtime to determine the correct code branch for a given implementation. The simplest way is:
See also
DOMParserand HTML5: DOM Parsing and Serialization (Working Draft).