123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using System;
- using System.IO;
- using System.Text;
- using System.Xml;
- using System.Xml.Serialization;
- namespace TEAMModelOS.SDK.Helper.Common.XmlHelper
- {
- public class Json2Xml
- {
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2612.0")]
- [System.SerializableAttribute()]
- [System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:ebay:apis:eBLBaseComponents")]
- public enum ItemSpecificSourceCodeType
- {
- /// <remarks/>
- ItemSpecific,
- /// <remarks/>
- Attribute,
- /// <remarks/>
- Product,
- /// <remarks/>
- CustomCode,
- }
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2612.0")]
- [System.SerializableAttribute()]
- [System.Diagnostics.DebuggerStepThroughAttribute()]
- [System.ComponentModel.DesignerCategoryAttribute("code")]
- [System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:ebay:apis:eBLBaseComponents")]
- public partial class NameValueListType
- {
- private string nameField;
- private string[] valueField;
- private ItemSpecificSourceCodeType sourceField;
- private bool sourceFieldSpecified;
- private System.Xml.XmlElement[] anyField;
- /// <remarks/>
- public string Name
- {
- get
- {
- return this.nameField;
- }
- set
- {
- this.nameField = value;
- }
- }
- /// <remarks/>
- [System.Xml.Serialization.XmlElementAttribute("Value")]
- public string[] Value
- {
- get
- {
- return this.valueField;
- }
- set
- {
- this.valueField = value;
- }
- }
- /// <remarks/>
- public ItemSpecificSourceCodeType Source
- {
- get
- {
- return this.sourceField;
- }
- set
- {
- this.sourceField = value;
- }
- }
- /// <remarks/>
- [System.Xml.Serialization.XmlIgnoreAttribute()]
- public bool SourceSpecified
- {
- get
- {
- return this.sourceFieldSpecified;
- }
- set
- {
- this.sourceFieldSpecified = value;
- }
- }
- /// <remarks/>
- [System.Xml.Serialization.XmlAnyElementAttribute()]
- public System.Xml.XmlElement[] Any
- {
- get
- {
- return this.anyField;
- }
- set
- {
- this.anyField = value;
- }
- }
- }
- public class CustomItemSpecifics
- {
- public NameValueListType[] ItemSpecifics;
- }
- public class Item
- {
- public string Name { get; set; }
- public string Value { get; set; }
- public string[] RecommValues { get; set; }
- //public void DataTable2Entity(Item item, DataRow dr) {
- // item.Name=dr.
- //}
- }
- public static string ObjectToText(Object inObject, Type inType)
- {
- String XmlizedString = null;
- MemoryStream ms = new MemoryStream();
- XmlSerializer xs = new XmlSerializer(inType);
- XmlTextWriter xmlTextWriter = new XmlTextWriter(ms, Encoding.UTF8);
- xs.Serialize(xmlTextWriter, inObject);
- ms = (MemoryStream)xmlTextWriter.BaseStream;
- XmlizedString = UTF8ByteArrayToString(ms.ToArray());
- return XmlizedString;
- }
- private static String UTF8ByteArrayToString(Byte[] characters)
- {
- UTF8Encoding encoding = new UTF8Encoding();
- String constructedString = encoding.GetString(characters);
- if (constructedString.Length > 0)
- {
- constructedString = constructedString.Substring(1);
- }
- return (constructedString);
- }
- public static Object TextToObject(string inText, Type inType)
- {
- try
- {
- if (string.IsNullOrEmpty(inText))
- {
- return null;
- }
- else
- {
- XmlSerializer xs = new XmlSerializer(inType);
- MemoryStream ms = new MemoryStream(StringToUTF8ByteArray(inText));
- XmlTextWriter xmlTextWriter = new XmlTextWriter(ms, Encoding.UTF8);
- return (Object)xs.Deserialize(ms);
- }
- }
- catch
- {
- return null;
- }
- }
- private static byte[] StringToUTF8ByteArray(string inText)
- {
- UTF8Encoding encoding = new UTF8Encoding();
- Byte[] byteArray = encoding.GetBytes(inText);
- return byteArray;
- }
- }
- }
|