The example in this article describes the ASP.net method of reading XML files and stream streams using the dataset's ReadXml. Share to everyone for your reference, specific as follows:
String strxml = "<xml><m><a>1</a><b>2</b></m><m><a>11</a ><b>22</b></m><m><a>111</a><b>222</b></m></xml> ";
DataSet ds = new DataSet ();
Stream stream = new MemoryStream (Encoding.Default.GetBytes (strxml));
Ds. READXML (stream);
Gridview1.datasource = ds;
Gridview1.databind ();
protected void Page_Load (object sender, EventArgs e) {if (!
IsPostBack) {DataSet ds = new DataSet (); TextReader reader = new StringReader (@ "<music> <song> <artist>the chi-
Lites</artist> <genre>Soul</genre> <album>a Lonely man</album> <year>1972</year> </song> <song> <ARTIST>BABYFACE&L t;/artist> <genre>R&B</genre> <album>unknown</album> &L
t;year></year> </song> <song> <artist>Babyface</artist>
<genre>R&B</genre> <album>the Essential Babyface</album> <year>2001</year> </song> <song> <artist>babyface</arti St> <genre>
R&b</genre> <album>grown and Sexy</album> <year>2005</year> </song> <song> <artist>maria arredondo</artist> <genr
E>pop</genre> <album>not going under</album> <year>2004</year> </song> <song> <artist>leona lewis</artist> <genre& Gt Pop</genre> <album>Unknown</album> <year>2008</year> < /song> <song> <artist>Usher</artist> <genre>r&b</genr
e> <album>Usher</album> <year>2008</year> </song> <song> <artist>christina aguilera</artist> <GENRE>BLUES</GENRE&G
T <aLbum>back to basics</album> <year>2004</year> </song> <son g> <artist>Sting</artist> <genre>Pop</genre> <album>s
Hape of my heart</album> <year></year> </song> </music>
"); Read the XML string used to receive the WebService return data ds.
READXML (reader, Xmlreadmode.auto); Generates an XML file//DS.
WriteXml (Server.MapPath ("Xml/song_bak.xml"));
Gridview1.datasource = ds;
Gridview1.databind ();
}
}
XML converted to DataSet///<summary>///returned by #region interface to DataSet///</summary>///<param name= "text" >xm L character </param>///<returns></returns> private DataSet GetDataSet (string text) {try {Xmltextreade
R reader = new XmlTextReader (new StringReader (text)); Reader.
WhitespaceHandling = WhitespaceHandling.None;
DataSet ds = new DataSet (); Ds.
READXML (reader); Reader.
Close (); Ds.
Dispose ();
return DS;
catch {return null; } #endregion #region the background to submit the data and get the data returned by the interface///<summary>///the backend data and get the data returned by the interface///</summary>///<param name= " RelativePath "> Address </param>///<returns></returns> public static string Getrequeststring (string
RelativePath) {string requesturl = RelativePath;
try {//Create an HTTP request HttpWebRequest requests = (System.Net.HttpWebRequest) webrequest.create (Requesturl); Request.
method = ' Get '; StreamReader Jsonstream = new StreamReader (Request. GetResponse (). GEtresponsestream ());
String jsonobject = Jsonstream.readtoend ();
return jsonobject; catch {return string.
Empty;
}} #endregion
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.