Code:
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE System-Link SYSTEM "SystemLinkRequest.dtd">
- <System-Linkxmlns:xsi="http:
- <Login userId="chris" password="password" maxIdle="30000" properties="com.mapics.cas.domain.EnvironmentId=MM, com.map
- ics.cas.domain.SystemName=AS400, com.mapics.cas.user.LanguageId=en" />
- </System-Link>
-
- static void Main(string[] args)
- {
- SystemLinkRequest.Login l = new SystemLinkRequest.Login();
- l.userId = "chris";
- l.password = "password";
- l.maxIdle = "30000";
- l.properties = "com.mapics.cas.domain.EnvironmentId=MM, com.mapics.cas.domain.SystemName=AS400, com.mapics.cas.user.LanguageId=en";
-
- SystemLinkRequest.SystemLink sl = new SystemLinkRequest.SystemLink();
- sl.Login = l;
-
- Console.WriteLine(SLXml2(sl));
-
- Console.ReadKey();
- }
-
- public static string SLXml2(SystemLinkRequest.SystemLink sl)
- {
- MemoryStream stream = null;
- myXmlTextWriter writer = null;
- try
- {
- stream = new MemoryStream();
-
- writer = new myXmlTextWriter(stream, Encoding.UTF8);
-
- XmlSerializer serializer = new XmlSerializer(typeof(SystemLinkRequest.SystemLink));
-
- serializer.Serialize(writer, sl);
-
- int count = (int)stream.Length;
-
- byte[] arr = new byte[count];
- stream.Seek(0, SeekOrigin.Begin);
-
- stream.Read(arr, 0, count);
-
- UTF8Encoding utf = new UTF8Encoding();
-
- return utf.GetString(arr).Trim();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- return string.Empty;
- }
- finally
- {
- if (stream != null) stream.Close();
- if (writer != null) writer.Close();
- }
- }
-
- public class myXmlTextWriter: XmlTextWriter
- {
-
- public myXmlTextWriter(Stream w, Encoding e)
- : base(w,e)
- { }
-
- public override void WriteStartDocument()
- {
- base.WriteStartDocument();
- this.WriteDocType("System-Link", null, "SystemLinkRequest.dtd", null);
- }
- }
|
|