Tag:io ar os sp file on div bs ad
Converts an XML object content string to a dataset public static DataSet Convertxmltodataset ( String xmlData) { stringreader stream = null; xmltextreader reader = null; try { dataset XmlDS = new DataSet (); stream = new StringReader ( XmlData); // Load from stream to xmltextreader reAder = new XmlTextReader (stream); xmlds.readxml (reader); return xmlds; } catch (System.Exception ex) { throw ex; } finally { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF (reader! = null) &nBsp; reader. Close (); } } //converting an XML file to dataset public static DataSet Convertxmlfiletodataset (string xmlfile) { StringReader stream = Null; xmltextreader Reader = null; try { xmldocument XMLD = new XmlDocument (); xmld. Load (xmlfile); dataset xmlds = new DataSet (); stream = new StringReader (XMLD. INNERXML); // Load from stream to xmltextreader reader = new XmlTextReader (stream); xmlds.readxml (reader); //xmlds.readxml (xmlfile); return xmlds; } &nBsp; catch (System.Exception ex) { throw ex; } finally { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF (reader! = null) reader. Close (); } } //Converting a DataSet to an XML object string public static string CONVERTDAtasettoxml (DataSet xmlds) { memorystream stream = null; xmltextwriter writer = null; try { stream = new MemoryStream (); // Load from stream to xmltextreader writer = new XmlTextWriter (stream, Encoding.unicode); //writing to the file using the WriteXml method . &nbsP; xmlds.writexml (writer); int count = (int) stream. Length; byte[] arr = new byte[count]; stream. Seek (0, Seekorigin.begin); stream. Read (arr, 0, Count); unicodeencoding UTF = new UnicodeEncoding (); return UTF. GetString (arr). Trim (); } catch (System.exceptiOn ex) { throw ex; } finally { if (writer! = null) writer. Close (); } } //Converting a DataSet to an XML file public static void Convertdatasettoxmlfile (DataSet xmlds, string xmlfile) &nBsp; { memorystream stream = Null; xmltextwriter writer = null; try { stream = new MemoryStream (); //loading from stream to xmltextreader writer = new XmlTextWriter (stream, Encoding.unicode); // Write the file using the WriteXml method . xmlds.writexml (writeR); int count = ( int) stream. Length; byte[] arr = new byte[count]; stream. Seek (0, Seekorigin.begin); stream. Read (arr, 0, Count); //return Unicode-encoded text unicodeencoding UTF = new UnicodeEncoding (); streamwriter SW = new StreamWriter (xmlfile); SW. WriteLine ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>"); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SW. WriteLine (UTF. GetString (arr). Trim ()); sw. Close (); } catch (System.Exception ex) { throw ex; } finally { if (writer! = null) writer. Close (); } }
C # Parsing XML to DataSet and dataset to XML file functions