2011-09-27 5 views
0

내 XML은 다음과 같습니다안드로이드에서 SAX xml Parser로부터 속성 값을 얻는 방법?

<?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); 

    } 


    } 

내가 parser.and 내가 모든 미디어 Atrribute 얻을 수 있습니다 SAX를 사용 : 컨텐츠를. 하지만 yt : format value를 얻을 수 없기 때문에 Android에서 yt : format 값을 얻을 수 있습니다.

+0

색소폰 [파서] (http://developerlife.com/tutorials/?p=29) – Uttam

답변

-1

attributes.getValue (5);를 사용할 수 있습니다.

+0

Isn 이거 꽤 약해? XML이 변경되면 어떻게 될까요? –

+0

예 ... Matthew .. –

0

attributes.getValue("yt:format") 또는 attributes.getValue("http://gdata.youtube.com/schemas/2007", "format")과 같이 표시되어야합니다.

+0

@ Matthew ..이 튜토리얼을 참조하십시오. 작동하지만 고맙습니다. 매개 변수는 "http://gdata.youtube"입니다. .com/schemas/2007 "? 그것은 반드시 또는 다른 것을 쓸 수 있습니다 –

+0

요소에 선언 된 네임 스페이스의 URL입니다 :'xmlns : yt = 'http : // gdata.youtube.com/schemas/2007'' –

+0

Thanks Matthew ... –

관련 문제