Modify RSS XML Feed for Windows 8 Using JavaScript

An RSS reader for Windows 8 is being created for a specific site. Everything works, except for the video [usually YouTube], as the website uses <object></object> to embed the video, not the <iframe> . the result is just a large block of empty objects wherever there is video.

My first instinct was to find and replace the <object></object> <iframe> tags and add the src attribute with the correct URL. I created a dummy application to check if this method will work, and the solution works if all you changed was static HTML.

Dummy app code:

 <body> <div style="text-align: center;"> <object width="853" height="480" id="test"> <param name="movie" value="http://www.youtube.com/v/2rDs7W3WRIk?version=3&amp;hl=en_US"></param> <param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param> <embed src="http://www.youtube.com/v/2rDs7W3WRIk?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="853" height="480" allowscriptaccess="always" allowfullscreen="true"></embed> </object></div> 

Wrote and named a function below that really works. Want to do something similar to an XML document:

  function setHTML5video() { var listOfSrcs = document.getElementsByTagName("embed"); for (var i = 0; i < listOfSrcs.length; i += 1) { var videoSrc = document.getElementsByTagName("embed")[i].getAttribute("src"); var newSrc = videoSrc.replace("/v/", "/embed/"); //var newNode = '<iframe width="853" height="480" src="' + newSrc + '" frameborder="0" allowfullscreen></iframe>'; var iFrame = document.createElement("iframe"); iFrame.setAttribute("src", newSrc); document.getElementsByTagName("object")[i].replaceNode(iFrame); //WinJS.Utilities.setOuterHTMLUnsafe(test, newNode); } } 

The end of the stub application code.

However, due to the lack of knowledge of the Windows 8 API, and despite the fact that he is responsible for the online response all day, I cannot find how to do the same with the XML feed that is downloaded from an external site. I probably missed something fundamental.

 function itemInvoked(z) { var currentArticle = articlesList.getAt(z.detail.itemIndex); WinJS.Utilities.setInnerHTMLUnsafe(articlecontent, currentArticle.content); articlelist.style.display = "none"; articlecontent.style.display = ""; mainTitle.innerHTML = currentArticle.title; WinJS.UI.Animation.enterPage(articlecontent); } 

When a user clicks on a thumbnail, the XML RSS feed for this article is pulled up and inserted into the file with id = "articlecontent". I want to change this channel before it is injected.

 <section id="content"> <div id="articlelist" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource: mmoNewsPosts.ItemList.dataSource, itemTemplate: MMOItemTemplate }"></div> <!-- Article Content --> <div id="articlecontent"></div> <!-- Article Content --> </section> 

Change, because there seems to be some confusion, I already have a loaded channel through WinJS.xhr:

  function downloadMMOFeed(FeedUrl) { WinJS.xhr({ url: FeedUrl, responseType: "xml" }).then(function (rss) { pageTitle = rss.responseXML.querySelector("title").textContent; mainTitle.innerHTML = pageTitle; var items = rss.responseXML.querySelectorAll("item"); //more stuff... for (var n = 0; n < items.length; n +=1) { article.content = items[n].querySelector("description").textContent; //more stuff... 
+4
source share
1 answer

Could you just load the XML feed into XHR and then parse the result before attaching it to the page? For instance:

  WinJS.xhr({ url: "http://www.w3schools.com/xml/note.xml", responseType: "xml" }) .done( function (request) { var text = request.responseText; //TODO : Parse the XML returned by the server which is in var text }); 

Windows 8 has no cross-domain restrictions, so it’s possible.

0
source

Source: https://habr.com/ru/post/1446147/


All Articles