Search code examples
xmlvb.netpodcastxmltextwriter

Using XmlTextWriter with iTunes podcast


I have the following code generating an XML podcast file for iTunes podcast:

Dim writer As New XmlTextWriter("c:\jdir\test.xml", System.Text.Encoding.UTF8)

writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 4

writer.WriteStartElement("channel")

writer.WriteStartElement("title")
writer.WriteString("My Podcast")
writer.WriteEndElement()
....etc etc..

But when i came to this part:

<itunes:image href="http://www.mywebsitehere.com/student.jpg" />        
<itunes:category text="Education">      
    <itunes:category text="Education Technology"/>      
</itunes:category>      
<itunes:category text="Higher Education"/>

I was unsure how to add the href= to the element itself and also the text=?

Any help would be great!


Solution

  • You can add href= and text = by using WriteAttributeString..

    Try the below code.. May be it will help you...

        writer.WriteStartElement("itunes:image")
        writer.WriteAttributeString("href", "http://www.mywebsitehere.com/student.jpg")
        writer.WriteEndElement()
        writer.WriteStartElement("itunes:category")
        writer.WriteAttributeString("text", "Education")
        writer.WriteStartElement("itunes:category", Nothing)
        writer.WriteAttributeString("text", "Education Technology")
        writer.WriteEndElement()
        writer.WriteEndElement()
        writer.WriteStartElement("itunes:category")
        writer.WriteAttributeString("text", "Education Technology")
        writer.WriteEndElement()