midrange.com code scratchpad
Name:
system-link xml
Scriptlanguage:
C#
Tabwidth:
4
Date:
01/13/2010 08:00:53 pm
IP:
Logged
Description:
The user was to lazy to give a description
Code:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE System-Link SYSTEM "SystemLinkRequest.dtd">
  3. <System-Linkxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  4. <Login userId="chris" password="password" maxIdle="30000" properties="com.mapics.cas.domain.EnvironmentId=MM, com.map
  5. ics.cas.domain.SystemName=AS400, com.mapics.cas.user.LanguageId=en" />
  6. </System-Link>
  7.  
  8.  static void Main(string[] args)
  9.         {
  10.             SystemLinkRequest.Login l = new SystemLinkRequest.Login();
  11.             l.userId = "chris";
  12.             l.password = "password";
  13.             l.maxIdle = "30000";
  14.             l.properties = "com.mapics.cas.domain.EnvironmentId=MM, com.mapics.cas.domain.SystemName=AS400, com.mapics.cas.user.LanguageId=en";
  15.  
  16.             SystemLinkRequest.SystemLink sl = new SystemLinkRequest.SystemLink();
  17.             sl.Login = l;
  18.  
  19.             Console.WriteLine(SLXml2(sl));
  20.  
  21.             Console.ReadKey();
  22.         }
  23.  
  24. public static string SLXml2(SystemLinkRequest.SystemLink sl)
  25.         {
  26.             MemoryStream stream = null;
  27.             myXmlTextWriter writer = null;
  28.             try
  29.             {
  30.                 stream = new MemoryStream(); 
  31.  
  32.                 writer = new myXmlTextWriter(stream, Encoding.UTF8);
  33.  
  34.                 XmlSerializer serializer = new XmlSerializer(typeof(SystemLinkRequest.SystemLink));
  35.  
  36.                 serializer.Serialize(writer, sl); 
  37.  
  38.                 int count = (int)stream.Length; 
  39.  
  40.                 byte[] arr = new byte[count];
  41.                 stream.Seek(0, SeekOrigin.Begin);
  42.  
  43.                 stream.Read(arr, 0, count);
  44.  
  45.                 UTF8Encoding utf = new UTF8Encoding();
  46.  
  47.                 return utf.GetString(arr).Trim();
  48.             }
  49.             catch (Exception ex)
  50.             {
  51.                 Console.WriteLine(ex.Message);
  52.                 return string.Empty;
  53.             }
  54.             finally
  55.             {
  56.                 if (stream != null) stream.Close();
  57.                 if (writer != null) writer.Close();
  58.             }
  59.         }
  60.  
  61. public class myXmlTextWriter: XmlTextWriter
  62.     {
  63.                 
  64.         public myXmlTextWriter(Stream w, Encoding e)
  65.             : base(w,e)
  66.         { }
  67.         
  68.         public override void WriteStartDocument()
  69.         {
  70.             base.WriteStartDocument();
  71.             this.WriteDocType("System-Link", null, "SystemLinkRequest.dtd", null);
  72.         }
  73.     }
© 2004-2019 by midrange.com generated in 0.015s valid xhtml & css