Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用SAXParse用java解析atom提要_Java_Parsing_Rss_Itunes_Atom Feed - Fatal编程技术网

如何使用SAXParse用java解析atom提要

如何使用SAXParse用java解析atom提要,java,parsing,rss,itunes,atom-feed,Java,Parsing,Rss,Itunes,Atom Feed,我使用SAXParser解析为iTunes播客准备的RSS提要。它不想使用这些标签。如果我删除所有标记的标签,它将工作。 主要任务是从项目标签获取信息 <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://w

我使用SAXParser解析为iTunes播客准备的RSS提要。它不想使用这些标签。如果我删除所有标记的标签,它将工作。 主要任务是从项目标签获取信息

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cc="http://web.resource.org/cc/"      xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<channel>
            <!-- With this tags I get error -->
    <atom:link href="" rel="self" type="application/rss+xml"/>
    <title></title>
    <pubDate></pubDate>
    <lastBuildDate></lastBuildDate>
    <generator></generator>
    <link></link>
    <language>en</language>
    <copyright><![CDATA[txt]]></copyright>
    <docs></docs>
    <managingEditor></managingEditor>
    <description><![CDATA[txt]]></description>
    <image>
        <url></url>
        <title></title>
        <link><![CDATA[]]></link>
    </image>
    <itunes:author></itunes:author>
    <itunes:keywords></itunes:keywords>
    <itunes:image href="" />
    <itunes:explicit>no</itunes:explicit>
    <itunes:summary><![CDATA[]]></itunes:summary>
    <itunes:subtitle><![CDATA[]]></itunes:subtitle>**
    <!-- *************************************************** -->    
        <item>
        <title>Title 1</title>
        <pubDate>Tue, 31 Dec 2013 14:24:00 +0000</pubDate>
        <guid isPermaLink="false"><![CDATA[7ef6ab037fe7f9e77a195b42fba84017]]></guid>
        <link><![CDATA[http://www.123.com]]></link>
        <itunes:image href="http://123.com/item/2613394" />
        <description><![CDATA[]]></description>
        <enclosure length="41999781" type="audio/mpeg" url="http://123.mp3" />
        <itunes:duration>43:45</itunes:duration>
        <itunes:explicit>clean</itunes:explicit>
        <itunes:keywords>learning,howto</itunes:keywords>
        <itunes:subtitle><![CDATA[]]></itunes:subtitle>
    </item>
</channel>
</rss>

EN
不
**
标题1
2013年12月31日星期二14:24:00+0000
43:45
清洁的
学习,如何
这就是DefaultHandler:

public class StudyHandler extends DefaultHandler {
private List<Track> track;
private Track currentTrack;
private StringBuilder builder;

boolean isTitle = false;

public List<Track> getMessages() {
    return this.track;
}

@Override
public void characters(char[] ch, int start, int length)
        throws SAXException {
    super.characters(ch, start, length);
    builder.append(ch, start, length);
    if (isTitle) {
        currentTrack.title = builder.toString();
    }
}

@Override
public void startDocument() throws SAXException {
    super.startDocument();

    track = new ArrayList<Track>();
    builder = new StringBuilder();
}

@Override
public void startElement(String uri, String localName, String name,
        Attributes attributes) throws SAXException {
    super.startElement(uri, localName, name, attributes);
    String value = localName.trim();
    if (value.equalsIgnoreCase("ITEM")) {
        this.currentTrack = new Track();
    } else if (value.equalsIgnoreCase("TITLE")) {
        isTitle = true;
    }

}

@Override
public void endElement(String uri, String localName, String name)
        throws SAXException {
    super.endElement(uri, localName, name);

    if (this.currentTrack != null) {
        if (localName.equalsIgnoreCase("TITLE")) {
            isTitle = false;
        } else if (localName.equalsIgnoreCase("ITEM")) {
            track.add(currentTrack);
        }
        builder.setLength(0);
    }
}
}
公共类StudyHandler扩展了DefaultHandler{
私有列表跟踪;
私人轨道;
私人建筑商;
布尔值=假;
公共列表getMessages(){
返回此.track;
}
@凌驾
公共无效字符(字符[]ch,整数开始,整数长度)
抛出SAX异常{
超级字符(ch、开始、长度);
builder.append(ch,start,length);
if(isTitle){
currentTrack.title=builder.toString();
}
}
@凌驾
public void startDocument()引发异常{
super.startDocument();
track=newarraylist();
生成器=新的StringBuilder();
}
@凌驾
public void startElement(字符串uri、字符串localName、字符串name、,
属性)引发SAX异常{
startElement(uri、localName、name、attributes);
字符串值=localName.trim();
if(值相等信号情况(“项目”)){
this.currentTrack=新磁道();
}else if(value.equalsIgnoreCase(“标题”)){
isTitle=真;
}
}
@凌驾
public void endElement(字符串uri、字符串localName、字符串名称)
抛出SAX异常{
super.endElement(uri、localName、name);
如果(this.currentTrack!=null){
if(localName.equalsIgnoreCase(“标题”)){
isTitle=假;
}else if(localName.equalsIgnoreCase(“项”)){
track.add(当前跟踪);
}
builder.setLength(0);
}
}
}

当您尝试跟踪每个开始/结束标记操作或在调试模式下时,是否注意到解析器正在解析标记


Anthony

这不是答案,你应该只在OP上发布类似这样的问题作为评论。如果你没有足够的代表发表评论,不要以此作为解决办法。人们会投你反对票,你只需要花更长的时间才能发表评论。