2013-11-01 193 views
1

我想解析下面给出的xml touchXml,我搜索并发现它使用名称空间,所以我需要使用名称空间来解析该XML。但任何人都可以引导我确切的名字空间来获取所有入口标签的子记录。我尝试了很多组合,但我认为我不知道如何获取条目标签数据。解析具有名称空间的XML

<?xml version="1.0" encoding="UTF-8" ?> 
<feed xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"> 
<id>tag:blogger.com,1999:blog-2497739505751584707</id> 
<updated>2012-03-16T22:56:53.663-07:00</updated> 
<title type="text">Recipes</title> 
<subtitle type="html" /> 
<link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://acaiberryrecipes.blogspot.com/feeds/posts/default" /> 
<link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2497739505751584707/posts/default" /> 
<link rel="alternate" type="text/html" href="http://acaiberryrecipes.blogspot.com/" /> 
<link rel="hub" href="http://pubsubhubbub.appspot.com/" /> 
<link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/2497739505751584707/posts/default?start-index=26&max-results=25" /> 
<author> 
    <name>default.com</name> 
    <uri>http://www.blogger.com/profile/05035355929944075160</uri> 
    <email>[email protected]</email> 
    <gd:image height="32" rel="http://schemas.google.com/g/2005#thumbnail" src="http://www.allauthentic.com/images/aalogo.gif" width="29" /> 
</author> 
<generator version="7.00" uri="http://www.blogger.com">Blogger</generator> 
<openSearch:totalResults>64</openSearch:totalResults> 
<openSearch:startIndex>1</openSearch:startIndex> 
<openSearch:itemsPerPage>25</openSearch:itemsPerPage> 
<entry> 
    <id>tag:blogger.com,1999:blog-2497739505751584707.post-5806304525333943936</id> 
    <published>2010-01-05T12:09:00.001-08:00</published> 
    <updated>2010-01-16T00:36:01.451-08:00</updated> 
    <title type="text">Welcome To Amazon Thunder! Check out our free recipes (updated), shopping list, easy ordering, and more! Please give us 5 stars in the app store</title> 
    <content type="html" /> 
    <link title="Post Comments" rel="replies" type="application/atom+xml" href="http://acaiberryrecipes.blogspot.com/feeds/5806304525333943936/comments/default" /> 
    <link title="0 Comments" rel="replies" type="text/html" href="http://acaiberryrecipes.blogspot.com/2010/01/welcome-to-amazon-thunder-on-your.html#comment-form" /> 
    <link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2497739505751584707/posts/default/5806304525333943936" /> 
    <link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2497739505751584707/posts/default/5806304525333943936" /> 
    <link title="Welcome To Amazon Thunder! Check out our free recipes (updated), shopping list, easy ordering, and more! Please give us 5 stars in the app store" rel="alternate" type="text/html" href="http://acaiberryrecipes.blogspot.com/2010/01/welcome-to-amazon-thunder-on-your.html" /> 
    <author> 
     <name>ALLAuthentic.com</name> 
     <uri>http://www.blogger.com/profile/05035355929944075160</uri> 
     <email>[email protected]</email> 
     <gd:image height="32" rel="http://schemas.google.com/g/2005#thumbnail" src="http://www.allauthentic.com/images/aalogo.gif" width="29" /> 
    </author> 
    <thr:total>0</thr:total> 
</entry> 
+0

是否使用NSXMLParserDelegate?让我准确地指出名称空间的含义。 –

+0

o对不起,我忘了提及解析器。我用touchxml解析\ –

回答

0

你的默认命名空间(这是什么进入似乎使用)是http://www.w3.org/2005/Atom按规定:

xmlns="http://www.w3.org/2005/Atom" 
0

NSDictionary *nameSpace=[NSDictionary dictionaryWithObjectsAndKeys: @" http://www.w3.org/2005/Atom ",@"xmlns", @" http://www.georss.org/georss ",@"georss", @" http://a9.com/-/spec/opensearchrss/1.0/ ",@"openSearch", @" http://schemas.google.com/blogger/2008 ",@"blogger", @" http://schemas.google.com/g/2005 ",@"gd", @" http://purl.org/syndication/thread/1.0 ",@"thr", nil]; resultNodes=[xmlDoc nodesForXPath:@"//xmlns:feed//xmlns:entry" namespaceMappings:nameSpace error:&error];

+0

这是问题的答案吗? –

+0

是的,这是我的问题的答案,希望它可以帮助别人 –

相关问题