View Single Post
  #5 (permalink)  
Old 09-16-08, 07:52 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
When you initialize the HtmlTextWriter, you can set the encoding there - that will setup the XML properly, then you just iterate your result set and write the nodes.

The following example is just static, but you could easily convert it to iterate your dataset and write dynamically. It's in C# so you may need to convert it but there are plenty of free converters online.

Also, you will probably need to convert it to write to the buffer rather than a file.

aspnet Code:
    using System; using System.IO; using System.Xml; public class Sample {   public static void Main()   {     XmlTextWriter writer = new XmlTextWriter("myMedia.xml", System.Text.Encoding.GetEncoding("utf-8"));     //Use automatic indentation for readability.     writer.Formatting = Formatting.Indented;             //Write the root element     writer.WriteStartElement("items");     //Start an element     writer.WriteStartElement("item");     //Add an attribute to the previously created element     writer.WriteAttributeString("rating", "R");           //add sub-elements     writer.WriteElementString("title", "The Matrix");     writer.WriteElementString("format", "DVD");     //End the item element     writer.WriteEndElement();  // end item       //Write some white space between nodes     writer.WriteWhitespace("\n");     //Write a second element using raw string data     writer.WriteRaw("<item>" +                     "<title>BloodWake</title>" +                     "<format>XBox</format>" +                     "</item>");     //Write a third element with formatting in the string     writer.WriteRaw("\n  <item>\n" +                     "    <title>Unreal Tournament 2003</title>\n" +                     "    <format>CD</format>\n" +                     "  </item>\n");     // end the root element     writer.WriteFullEndElement();                   //Write the XML to file and close the writer     writer.Close();    } }
__________________
"Political Correctness is a doctrine, fostered by a delusionary, illogical, liberal minority and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end."
Reply With Quote