Как получить значение атрибута из SAX xml Parser в Android? - PullRequest
0 голосов
/ 27 сентября 2011

мой XML:

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'
    xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>

    <media:group>

        <media:content
            url='http://www.youtube.com/v/UBCNwgFlw1A?f=videos&amp;app=youtube_gdata'
            type='application/x-shockwave-flash' medium='video' isDefault='true'
            expression='full' duration='217' yt:format='5' />
        <media:content
            url='rtsp://v4.cache7.c.youtube.com/CiILENy73wIaGQlQw2UBwo0QUBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp'
            type='video/3gpp' medium='video' expression='full' duration='217'
            yt:format='1' />
        <media:content
            url='rtsp://v2.cache6.c.youtube.com/CiILENy73wIaGQlQw2UBwo0QUBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp'
            type='video/3gpp' medium='video' expression='full' duration='217'
            yt:format='6' />

    </media:group>

</entry>

.java файл

public void startElement(String arg0, String localName, String arg2,
        Attributes attributes) throws SAXException {
    currentElement = true;

if (localName.equals("content")) {

        String videourl = attributes.getValue("url");
        Log.v("log_tag", "Video url is : " + videourl);
        message.setVideourl(videourl);


        String duration = attributes.getValue("duration");
        Log.v("log_tag", "Duration of Video is : " + duration);


        String formaturl1 = attributes.getValue("format");

        Log.v("log_tag", "format of url is : " + formaturl);

    }


   }

Я использовал SAX parser.и я могу получить все атрибуты медиа: содержимого.Но я не могу получить значение yt: format, так как я могу получить значение yt: format в Android.

Ответы [ 2 ]

0 голосов
/ 28 сентября 2011

вы можете использовать attribute.getValue (5);

0 голосов
/ 27 сентября 2011

Похоже, attributes.getValue("yt:format") или attributes.getValue("http://gdata.youtube.com/schemas/2007", "format") должны оба работать.

...