2012-08-17 4 views
1

하여 XML 내용을 사용하여, 다른 NS 존재 위치 :문제 동일한 요소 JQuery와에게

<?xml version="1.0"?> 
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:atom="http://www.w3.org/2005/Atom"> 
    <channel> 
     <title>Some Title.</title> 
     <description>Pipes Output</description> 
     <link>http://pipes.yahoo.com/pipes/pipe.info</link> 
     <atom:link rel="next" href="http://pipes.yahoo.com/pipes/pipe.run"/> 
     <pubDate>Fri, 17 Aug 2012 07:25:28 +0000</pubDate> 
     <generator>http://pipes.yahoo.com/pipes</generator> 
     <item> 
     <title>Title 1</title> 
     <link>http://feedproxy.google.com</link> 
     <description>there is no description for this</description> 
     <guid isPermaLink="false">http://wordpress.com</guid> 
     <pubDate>Thu, 16 Aug 2012 16:47:41 +0000</pubDate> 
     <media:content medium="image" url=""> 
      <media:title type="html">some media</media:title> 
     </media:content> 
     <media:content medium="image" url=""> 
      <media:title type="html">Image</media:title> 
     </media:content> 
     <media:content medium="image" url=""> 
      <media:title type="html">Image</media:title> 
     </media:content> 
     <media:content medium="image" url=""> 
      <media:title type="html">Image</media:title> 
     </media:content> 
     <category>News</category> 
     </item>   
     <item> 
     <title>title 3</title> 
     <link>http://google.com</link> 
     <description>some description</description> 
     <author>Self</author> 
     <guid isPermaLink="false"></guid> 
     <pubDate>Wed, 15 Aug 2012 17:43:32 +0000</pubDate> 
     <enclosure type=""/> 
     </item> 

    </channel> 
</rss> 

로서 어떤 항목 <media:content> 요소

JQuery와 XML을 분석하는 몇몇 그다지이 관찰

function loadNews() 
{ 
    var entries = []; 
    var selectedEntry = ""; 
    $loadMore = $('#btn_loadmore'); 
    $loadMore.hide(); 
    var RSS = "news.xml";      
//$.get(RSS, {}, function(res, code) { 
    $.ajax(
    { 
     type: "POST", 
     url: "news.xml",        
     dataType: "xml", 
     async: false, 
     success: function(res){ 
     var xml = $(res); 
     var items = xml.find("item"); 
     $.each(items, function(i, v) { 
     entry = { 
      title:$(v).find("\\:title, title").text(), 
      link:$(v).find("link").text().replace(/\/+$/, ""), 
      description:$.trim($(v).find("description").text()) 
    }; 
    entries.push(entry); 
    }); 

    var s = ''; 
    for(i=0;i<10;i++) 
    { 
     console.log(i + "--------------------------"); 
     if(i>=entries.length) 
     break; 
     alert(entries[i].title); 
     console.log(entries[i].description); 
     console.log(entries[i].link); 
    } 
    } 
    });             
} 

문제 :

다음과 같다

위의 코드는 Firefox에서 잘 작동합니다. 은 그러나 사파리 미디어 태그 안의 텍스트는 파이어 폭스의 제목에

출력이 추가됩니다 : 사파리에서 Title 1

출력 : Title 1some mediaImageImageImage

편집 : 어떻게 내가 선택을 말할까요 <media:title>을 선택하지 그러나 단지 <title>

나는 post을 통과했지만 아무런 도움이되지 않았습니다.

내가 무엇이 누락 되었습니까?

내가 사용하고 * JQuery와 1.7.1, 문제는. ****

+0

'$ (res)'대신'$ .parseXML (res)'를 사용하면 문제가 지속됩니까? –

+0

잘 parseXML 문자열을 XML 문서로 구문 분석합니다. 하지만 성공 함수에서 얻는 결과는 이미 xml 개체입니다. 또한 내가 무슨 말을했는데 그것은 컴파일 오류를 제공합니다. 파이어 폭스에 그것은 말한다 : 구문 오류 \t [개체 XMLDocument] –

답변

0

사용 find('[nodeName="title"]').text() 대신 find("\\:title, title").text()

JQuery와 1.6와 동일 **입니다 그러나 이것은 JQuery와 1.6와 함께 작동, 난 jquery 1.7.1과 동일하게하고 싶다