XML parsing question

NJDude

Expert
Licensed User
Longtime User
I've been searching for examples but I could not find one to help me with this particular case.

The XML extract below, how do I get the DURATION (01:12:21) using the XMLSax parser?

B4X:
- <item>
      <title>Podcast: Episode 1</title> 
      <link>http://www.somewebsite.com/podcast1.mp3</link> 
      <comments>http://www.somewebsite.com/podcast1.mp3</comments> 
      <itunes:author>John Doe</itunes:author> 
      <dc:creator>Creator Name</dc:creator> 
      <description>Some description here.</description> 
      <pubDate>Thu, 09 Jun 2011 00:00:00 EST</pubDate> 
      <itunes:subtitle /> 
      <itunes:summary /> 
      <itunes:keywords>test1, test2</itunes:keywords> 
      <itunes:duration>01:12:21</itunes:duration>  '<<=== THIS LINE!!!
      <enclosure url="http://www.somewebsite.com/podcast1.mp3" length="87031808" type="audio/mpeg" /> 
      <guid>http://www.somewebsite.com/podcast1.mp3</guid> 
      <itunes:explicit>no</itunes:explicit> 
  </item>

Thanks.
 

vb1992

Well-Known Member
Licensed User
Longtime User
I'm thinking something like this.....

Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)


If Parser.Parents.IndexOf("item") > -1 Then
If Name = "itunes:duration" Then

Log("Duration: " & Text.ToString & CRLF)

End If
End If


End sub


B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
   
    
                  If Parser.Parents.IndexOf("item") > -1 Then
                         If Name = "itunes:duration" Then
          
                            Log("Duration: " & Text.ToString & CRLF)
      
                    End If
                End If   
   

End sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Ok, this is weird, I tried that before but now it's working, to get it, I did this:

B4X:
If Name = "duration" Then
          
   Duration = Text.ToString

End If

I need to learn more about how to parse XMLs using B4A :D
 
Upvote 0
Top