Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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
Java Android SAX XML解析器访问机柜标记URL属性_Java_Android_Xml_Xml Parsing_Sax - Fatal编程技术网

Java Android SAX XML解析器访问机柜标记URL属性

Java Android SAX XML解析器访问机柜标记URL属性,java,android,xml,xml-parsing,sax,Java,Android,Xml,Xml Parsing,Sax,我创建了一个包含详细视图的XML解析器。我正在阅读一个包含附件标签的RSS提要。我正在尝试从附件标记获取视频文件的URL 这是机柜标记的外观: 每次我试图检索它时,解析器都返回null。我该怎么办 这是显示可能导致问题的解析器结果的部分: // TESTING HERE! String enclosure = b.getString("enclosure"); // What is getting displayed theTitle = b.getString("title").trim()

我创建了一个包含详细视图的XML解析器。我正在阅读一个包含附件标签的RSS提要。我正在尝试从附件标记获取视频文件的URL

这是机柜标记的外观:

每次我试图检索它时,解析器都返回null。我该怎么办

这是显示可能导致问题的解析器结果的部分:

// TESTING HERE!
String enclosure = b.getString("enclosure");
// What is getting displayed
theTitle = b.getString("title").trim();
theDate = newDateStr;
theStory = b.getString("description") + "\n\nView in full website:\n" + b.getString("link")+ "\n\nDownload teaching:\n" + enclosure;
这是Rshandler类:

public class RSSHandler extends DefaultHandler 
{

RSSFeed _feed;
RSSItem _item;
String _lastElementName = "";
boolean bFoundChannel = false;
final int RSS_TITLE = 1;
final int RSS_LINK = 2;
final int RSS_DESCRIPTION = 3;
final int RSS_ENCLOSURE = 4;
final int RSS_PUBDATE = 5;

int depth = 0;
int currentstate = 0;
/*
 * Constructor 
 */
RSSHandler()
{
}

/*
 * getFeed - this returns the feed when all of the parsing is complete
 */
RSSFeed getFeed()
{
    return _feed;
}


public void startDocument() throws SAXException
{
    // Initialize RSSFeed object - this will hold parsed contents
    _feed = new RSSFeed();
    // Initialize the RSSItem object - we will use this as a crutch to grab the info from the channel
    // because the channel and items have very similar entries..
    _item = new RSSItem();

}
public void endDocument() throws SAXException
{
}
public void startElement(String namespaceURI, String localName,String qName, Attributes atts) throws SAXException
{
    depth++;
    if (localName.equals("channel"))
    {
        currentstate = 0;
        return;
    }
    if (localName.equals("image"))
    {
        // Record feed data - Temporarily stored it in the item
        _feed.setTitle(_item.getTitle());
        _feed.setPubDate(_item.getPubDate());
    }
    if (localName.equals("item"))
    {
        // create a new item
        _item = new RSSItem();
        return;
    }
    if (localName.equals("title"))
    {
        currentstate = RSS_TITLE;
        return;
    }
    if (localName.equals("description"))
    {
        currentstate = RSS_DESCRIPTION;
        return;
    }
    if (localName.equals("link"))
    {
        currentstate = RSS_LINK;
        return;
    }
    if (localName.equals("enclosure"))
    {
        currentstate = RSS_ENCLOSURE;
        return;
    }
    if (localName.equals("pubDate"))
    {
        currentstate = RSS_PUBDATE;
        return;
    }
    // If I don't explicitly handle the element and to make sure I don't wind up erroneously 
    // storing a newline or other fake data into one of our existing elements
    currentstate = 0;
}

public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
    depth--;
    if (localName.equals("item"))
    {
        // Add the item to the list!
        _feed.addItem(_item);
        return;
    }
}

public void characters(char ch[], int start, int length)
{
    String theString = new String(ch,start,length);
    Log.i("RSSReader","characters[" + theString + "]");

    switch (currentstate)
    {
        case RSS_TITLE:
            _item.setTitle(theString);
            currentstate = 0;
            break;
        case RSS_LINK:
            _item.setLink(theString);
            currentstate = 0;
            break;
        case RSS_DESCRIPTION:
            _item.setDescription(theString);
            currentstate = 0;
            break;
        case RSS_ENCLOSURE:
            _item.setEnclosure(theString);
            currentstate = 0;
            break;
        case RSS_PUBDATE:
            _item.setPubDate(theString);
            currentstate = 0;
            break;
        default:
            return;
    }

}
}
这是RSSFeed类:

public class RSSFeed 
{
private String _title = null;
private String _pubdate = null;
private String _enclosure = null;
private int _itemcount = 0;
private List<RSSItem> _itemlist;


RSSFeed()
{
    _itemlist = new Vector<RSSItem>(0); 
}
int addItem(RSSItem item)
{
    _itemlist.add(item);
    _itemcount++;
    return _itemcount;
}
RSSItem getItem(int location)
{
    return _itemlist.get(location);
}
List<RSSItem> getAllItems()
{
    return _itemlist;
}
int getItemCount()
{
    return _itemcount;
}
void setTitle(String title)
{
    _title = title;
}
void setPubDate(String pubdate)
{
    _pubdate = pubdate;
}
void setEnclosure(String enclosure)
{
    _enclosure = enclosure;
}
String getTitle()
{
    return _title;
}
String getPubDate()
{
    return _pubdate;
}
String getEnclosure()
{
    return _enclosure;
}
}

url标记是一个属性,因此要访问它,可以调用
attributes.getValue(“url”)localName
为“enclosure”时,startElement中的code>。

在您的?您的对象都没有定义
getString(String)
方法。b是我用来将数据从一个类传输到另一个类的包的名称,如下所示:bundle b=startingIntent.getBundleExtra(“android.intent.extra.intent”);
public class RSSItem 
{
    private String _title = null;
    private String _description = null;
    private String _link = null;
    private String _enclosure = null;
    private String _pubdate = null;


RSSItem()
{
}
void setTitle(String title)
{
    _title = title;
}
void setDescription(String description)
{
    _description = description;
}
void setLink(String link)
{
    _link = link;
}
void setEnclosure(String enclosure)
{
    _enclosure = enclosure;
}
void setPubDate(String pubdate)
{
    _pubdate = pubdate;
}
String getTitle()
{
    return _title;
}
String getDescription()
{
    return _description;
}
String getLink()
{
    return _link;
}
String getEnclosure()
{
    return _enclosure;
}
String getPubDate()
{
    return _pubdate;
}
public String toString()
{
    // limit how much text we display
    if (_title.length() > 42)
    {
        return _title.substring(0, 42) + "...";
    }
    return _title;
}
 }