2011-09-13 3 views
2

QML로 RSS 피드를 구문 분석하고 싶습니다. 내용 태그, 난 문자열로 QML과 URL을 구문 분석 할 수있는 방법 :RSS QML로 구문 분석

공급 구조는 미디어입니다

<channel> 
<item> 
<title> 
</title> 
<description> 
</description> 
<media:content url="http://someURLHere.com/avatar/somethingHere?s=96&#38;d=identicon&#38;r=G" medium="image"> 
</media:content> 
</item> 

내 문제처럼 보인다?

답변

2

coyotte508의 답변에 댓글을 추가 할 수 없으므로 여기 대신 XmlListModel의 namespaceDeclarations 속성을 사용하여 '미디어'에 대한 네임 스페이스를 추가해야 할 수도 있습니다. 예 :

XmlListModel { 
    ... 
    namespaceDeclarations: "declare namespace media = 'http://put/the/path/here';" 
    XmlRole { name: "url"; query: "media:content/@url/string()" } 
} 
+0

감사합니다. harriha,이게 문제를 해결했습니다. – belhawary

0

http://doc.qt.nokia.com/4.7-snapshot/qml-xmllistmodel.html와 기본적으로 http://doc.qt.nokia.com/4.7-snapshot/qml-xmlrole.html

를 참조하십시오

XmlModel { 
    id: mymodel 
    xml: "blabblabla" /* you can also use source: to read directly from the web */ 
    query: "/rss/channel/item/" 

    XmlRole { 
    name: "url" 
    query: "media:content/@url/string()" 
    } 
} 

그리고 그것을 검색 :

mymodel.get(0).url 

을 여러 채널, 각 URL을 검색하려는 경우, 당신이 할 수있는 mymodel.count를 사용하여 채널 수를 얻고 mymodel.get (i)을 사용하여 각 채널에 액세스하십시오.

+0

내가 얻을 것은 QML XmlRole : 유효하지 않은 조회 : "미디어 : 컨텐츠/@의 URL/문자열()" – belhawary

+0

그런 다음 미디어/URL/문자열 @ 미디어/@ URL이/문자열을(), 시도(), @media : content/url/string() 또는 XmlModel.query를 "/ rss/channel/item/media : content"로 변경하고 XmlRole.query를 "@ url/string()"으로 변경하고 ":함유량". 그 중 하나가 작동하는지 확인하십시오. – coyotte508