366 CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION The next code section starts writing the XML stream, using the WriteStartDocument() method to generate the XML declaration. The WriteStartElement() method creates the root element, and sets the version attribute of this element to 2.0: XMLFeed.WriteStartDocument() XMLFeed.WriteStartElement(”rss”) XMLFeed.WriteAttributeString(”version”, “2.0″) Next, the code creates the element along with the
http://www.apress.com The latest XML browser news. The code generates the remaining elements by looping through the content in the DataView. It accesses each data row in the rows collection. Each time the code finds a news item, it writes a starting element and adds the and elements. The WriteElementString() method creates the opening tag, adds the specified text, and generates the closing tag: For Each dr As DataRow In dv.Table.Rows XMLFeed.WriteStartElement(”item”) XMLFeed.WriteElementString(”title”, dr(”newsTitle”).ToString()) XMLFeed.WriteElementString(”description”, dr(”newsDescription”).ToString()) XMLFeed.WriteEndElement() Next The script block finishes by writing the closing elements for each of the elements created earlier. It also calls the Flush() method to flush whatever is in the buffer to the stream, and it uses the Close() method to close the stream: We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.
This entry was posted
on Saturday, December 29th, 2007 at 12:20 am and is filed under Tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.