asp.net generate XML documents and send to client code

Source: Internet
Author: User

ASP tutorial. NET generates XML documents and sends them to client code
2 parameters, one is the URL, one is the parameter is your XML

public static string SendRequest (String uri, String poscontent)
{
String responsetext = "";
Try
{
StreamReader reader;
Here you can set the encoding
byte[] Postbody = System.Text.Encoding.Default.GetBytes (poscontent);
HttpWebRequest request = (HttpWebRequest) webrequest.create (URI);
Request. method = "POST";
Request. ContentType = "application/x-www-form-urlencoded";
Request. ContentLength = Postbody.length;
Request. AllowWriteStreamBuffering = true;

Stream DataStream = Request. GetRequestStream ();
Datastream.write (postbody, 0, postbody.length);
Datastream.close ();
HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
DataStream = Response. GetResponseStream ();
Encoding encode = System.Text.Encoding.GetEncoding ("UTF-8");
reader = new StreamReader (dataStream, encode);

ResponseText = reader. ReadToEnd ();
Reader. Close ();
Datastream.close ();
Response. Close ();
}
catch (Exception e)
{
Logger.writeln ("Fetch data from server failed");
}
return responsetext;
}


Method Two

Using System;
Using System.Xml;

Namespace WriteXml
{
Class Class1
{
static void Main (string[] args)
{
To create an instance object of the XmlTextWriter class
XmlTextWriter textWriter = new XmlTextWriter ("C:\myXmFile.xml", null);

Start the write process and invoke the WriteStartDocument method
Textwriter.writestartdocument ();

Write description
Textwriter.writecomment ("The Comment XmlTextWriter Sample Example");
Textwriter.writecomment ("Myxmlfile.xml in Root dir");

Write an element
Textwriter.writestartelement ("Name", "");
Textwriter.writestring ("Student");
Textwriter.writeendelement ();

And then write an element
Textwriter.writestartelement ("Address", "");
Textwriter.writestring ("Colony");
Textwriter.writeendelement ();

Write characters
char [] ch = new CHAR[3];
Ch[0] = ' a ';
CH[1] = ' R ';
CH[2] = ' C ';
Textwriter.writestartelement ("Char");
Textwriter.writechars (ch, 0, ch. Length);
Textwriter.writeendelement ();

Write document end, call WriteEndDocument method
Textwriter.writeenddocument ();

Close TextWriter
Textwriter.close ();
}
}
}

%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.