Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Read xml nodes

$
0
0

Hello, i have a form that reads xml data and everything is woring but i'm not sure how to get the data from a child node. here is my code.

this function is called when a file is selected

    Private Sub ReadSingleFile()
        Try
            Dim xmlDoc As New XmlDocument()
            xmlDoc.LoadXml(_newFileInfo.FFprobeStandardOutput)
            Dim nodeList As XmlNodeList = xmlDoc.GetElementsByTagName("stream")
            MediaTags.AudioTrackCount = 0
            For Each elem As XmlNode In nodeList
                Dim indexNode As XmlNode = elem.Attributes("index")
                Dim codecTypeNode As XmlNode = elem.Attributes("codec_type")
                Dim codecNameNode As XmlNode = elem.Attributes("codec_name")
                Dim profileNode As XmlNode = elem.Attributes("profile")
                Dim widthNode As XmlNode = elem.Attributes("width")
                Dim heightNode As XmlNode = elem.Attributes("height")
                Dim sampleRateNode As XmlNode = elem.Attributes("sample_rate")
                Dim channelsNode As XmlNode = elem.Attributes("channel_layout")

                Dim track As Integer
                Dim trackType = ""
                Dim trackCodec = ""
                Dim profile = ""
                Dim resolution = ""
                Dim sampleRate = ""
                Dim channels = ""

                If indexNode IsNot Nothing Then
                    track = Convert.ToInt32(indexNode.Value)
                End If
                If codecTypeNode IsNot Nothing Then
                    trackType = codecTypeNode.Value
                End If
                If codecNameNode IsNot Nothing Then
                    trackCodec = codecNameNode.Value
                End If
                If profileNode IsNot Nothing Then
                    profile = " (" & profileNode.Value & "),"
                End If
                If widthNode IsNot Nothing And heightNode IsNot Nothing Then
                    resolution = " " & widthNode.Value & "x" & heightNode.Value
                End If
                If sampleRateNode IsNot Nothing Then
                    sampleRate = " " & sampleRateNode.Value & " Hz,"
                End If
                If channelsNode IsNot Nothing Then
                    channels = channelsNode.Value
                End If

                If trackType = "video" Then
                    MediaTags.VideoTrackID() = track
                    MediaTags.VideoCodec = trackCodec
                    lbStreams.Items.Add("Track " & track & ": " & FirstCharToUpper(trackType) & ": " & trackCodec & profile & resolution)
                ElseIf trackType = "audio" Then
                    MediaTags.AudioTrackID = track
                    MediaTags.AudioCodec = trackCodec
                    lbStreams.Items.Add("Track " & track & ": " & FirstCharToUpper(trackType) & ": " & trackCodec & profile & sampleRate & " " & channels)
                ElseIf trackType = "subtitle" Then
                    lbStreams.Items.Add("Track " & track & ": " & FirstCharToUpper(trackType) & ": " & AllCharToUpper(trackCodec))
                End If
            Next elem
        Catch ex As Exception
            If My.MySettings.Default.WriteErrorLogFiles Then
                Try
                    Dim errorWriter As New StreamWriter(My.MySettings.Default.LogPath & "\error_log.txt", True)
                    errorWriter.WriteLine("An error has occurred while reading file tracks info in function ReadSingleFile")
                    errorWriter.WriteLine(ex.Message)
                    errorWriter.WriteLine(ex.ToString)
                    errorWriter.Flush()
                    errorWriter.Close()
                    errorWriter.Dispose()
                Catch ex1 As Exception
                    MessageBox.Show(ex1.Message)
                End Try
            End If
        End Try
    End Sub

here is my xml data

<streams><stream
          index="0"
          codec_name="h264"
          profile="Main"
          codec_type="video"
          width="720"
          height="404"><disposition
              default="1"
              dub="0"
              original="0"/><tag key="creation_time" value="2014-12-03 17:15:35"/><tag key="language" value="und"/><tag key="encoder" value="JVT/AVC Coding"/></stream><stream
          index="1"
          codec_name="aac"
          profile="LC"
          codec_type="audio"
          sample_rate="48000"
          channels="6"
          channel_layout="5.1"><disposition
              default="1"
              dub="0"
              original="0"/><tag key="creation_time" value="2014-12-03 17:15:35"/><tag key="language" value="eng"/></stream><stream
          index="2"
          codec_name="mov_text"
          codec_type="subtitle"><disposition
              default="1"
              dub="0"
              original="0"/><tag key="creation_time" value="2014-12-03 17:15:35"/><tag key="language" value="und"/></stream></streams>

As you can see this is for media files and I'm trying to get the language from each track whick is layed out a little funny but thats how ffprobe outputs it. any help would be great, thanks


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>