本文整理汇总了C#中XmlSerializer类的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializer类的具体用法?C# XmlSerializer怎么用?C# XmlSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSerializer类属于命名空间,在下文中一共展示了XmlSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeObject
public Object DeserializeObject(String pXmlizedString)
{
XmlSerializer xs = new XmlSerializer(typeof(EntryList));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return xs.Deserialize(memoryStream);
}
示例2: WMIBMySQL
public WMIBMySQL()
{
string file = Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml";
Core.RecoverFile(file);
if (File.Exists(file))
{
Syslog.WarningLog("There is a mysql dump file from previous run containing mysql rows that were never successfuly inserted, trying to recover them");
XmlDocument document = new XmlDocument();
using (TextReader sr = new StreamReader(file))
{
document.Load(sr);
using (XmlNodeReader reader = new XmlNodeReader(document.DocumentElement))
{
XmlSerializer xs = new XmlSerializer(typeof(Unwritten));
Unwritten un = (Unwritten)xs.Deserialize(reader);
lock (unwritten.PendingRows)
{
unwritten.PendingRows.AddRange(un.PendingRows);
}
}
}
}
Thread reco = new Thread(Exec) {Name = "MySQL/Recovery"};
Core.ThreadManager.RegisterThread(reco);
reco.Start();
}
示例3: Save
public override void Save(TelemetryLap lap)
{
try
{
if (lap == null)
return;
var filename = GetFileName(lap);
if (File.Exists(filename))
File.Delete(filename);
var xmlSer = new XmlSerializer(typeof (TelemetryLap));
using (var memStm = new MemoryStream())
{
xmlSer.Serialize(memStm, lap);
using (var stmR = new StreamReader(memStm))
{
memStm.Position = 0;
File.AppendAllText(filename, stmR.ReadToEnd(), Encoding.UTF8);
}
}
} catch (Exception ex)
{
logger.Error("Could not save xml telemetry lap", ex);
throw ex;
}
}
示例4: Read
private void Read(string filename)
{
XmlSerializer ser=new XmlSerializer(typeof(DataSet));
FileStream fs=new FileStream(filename, FileMode.Open);
DataSet ds;
ds=(DataSet)ser.Deserialize(fs);
fs.Close();
Console.WriteLine("DataSet name: "+ds.DataSetName);
Console.WriteLine("DataSet locale: "+ds.Locale.Name);
foreach(DataTable t in ds.Tables)
{
Console.WriteLine("Table name: "+t.TableName);
Console.WriteLine("Table locale: "+t.Locale.Name);
foreach(DataColumn c in t.Columns)
{
Console.WriteLine("Column name: "+c.ColumnName);
Console.WriteLine("Null allowed? "+c.AllowDBNull);
}
foreach(DataRow r in t.Rows)
{
Console.WriteLine("Row: "+(string)r[0]);
}
}
}
示例5: Run
public override int Run(string[] args)
{
string schemaFileName = args[0];
string outschemaFileName = args[1];
XmlTextReader xr = new XmlTextReader(schemaFileName);
SchemaInfo schemaInfo = SchemaManager.ReadAndValidateSchema(xr, Path.GetDirectoryName(schemaFileName));
schemaInfo.Includes.Clear();
schemaInfo.Classes.Sort(CompareNames);
schemaInfo.Relations.Sort(CompareNames);
XmlSerializer ser = new XmlSerializer(typeof(SchemaInfo));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", SchemaInfo.XmlNamespace);
using (FileStream fs = File.Create(outschemaFileName))
{
try
{
ser.Serialize(fs, schemaInfo, ns);
}
finally
{
fs.Flush();
fs.Close();
}
}
return 0;
}
示例6: GetDefault
public config GetDefault()
{
config config;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.buy4.com/api/toolbar/config.xml");
request.KeepAlive = false;
request.Method = "GET";
request.ContentType = "text/xml";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XmlSerializer serializer = new XmlSerializer(typeof(config));
Stream stream = response.GetResponseStream();
using (XmlReader reader = XmlReader.Create(stream))
{
config = (config)serializer.Deserialize(reader);
}
stream.Close();
return config;
}
示例7: ExportProteinSettings
public void ExportProteinSettings()
{
try
{
CutParametersContainer exportParams = new CutParametersContainer();
foreach (CutObject cuto in SceneManager.Get.CutObjects)
{
CutObjectProperties props = new CutObjectProperties();
props.ProteinTypeParameters = cuto.IngredientCutParameters;
props.Inverse = cuto.Inverse;
props.CutType = (int)cuto.CutType;
props.rotation = cuto.transform.rotation;
props.position = cuto.transform.position;
props.scale = cuto.transform.localScale;
exportParams.CutObjectProps.Add(props);
}
////write
serializer = new XmlSerializer(typeof(CutParametersContainer));
stream = new FileStream(path, FileMode.Create);
serializer.Serialize(stream, exportParams);
stream.Close();
}
catch(Exception e)
{
Debug.Log("export failed: " + e.ToString());
return;
}
Debug.Log("exported cutobject settings to " + path);
}
示例8: GetStdAsync
public async Task<SummaryTemperatureData> GetStdAsync()
{
// var uri = new Uri("http://jeffa.org:81/ha/SummaryData.php");
//var uri = new Uri(App.SummaryDataUrl);
//var client = new HttpClient();
//var opContent = (await client.GetAsync(uri)).Content;
//string foo = await opContent.ReadAsStringAsync();
//var fooo = JsonConvert.DeserializeObjectAsync<SummaryTemperatureData>(foo);
//return await fooo;
var applicationDataSettingsService = new ApplicationDataSettingsService();
try
{
// ToDo need to wrap this a bit. error checking. disposal....
WebHeaderCollection headers = new WebHeaderCollection();
WebRequest request = WebRequest.Create(new Uri(applicationDataSettingsService.SummaryDataUrl));
request.ContentType = "application/xml";
WebResponse response = await request.GetResponseAsync();
// response.Close(); // ?? hmmm
Debug.WriteLine("\nThe HttpHeaders are \n{0}", request.Headers);
Stream inputStream = response.GetResponseStream();
XmlReader xmlReader = XmlReader.Create(inputStream);
XmlSerializer xml = new XmlSerializer(typeof(SummaryTemperatureData));
var stdXml = (SummaryTemperatureData)xml.Deserialize(xmlReader);
return stdXml;
}
catch (Exception e)
{
Utility.Log(this, e.ToString());
return null;
}
}
示例9: StripResponseElement
public PipelineContinuation StripResponseElement(ICommunicationContext context)
{
var passedApiUrl
= (string)context.PipelineData["ApiUrl"];
if (string.IsNullOrEmpty(passedApiUrl))
return PipelineContinuation.Continue;
var xmlDocument
= (XmlDocument)context.PipelineData["ApiXmlResponse"];
// read and remove response header to get result
var responseElement = xmlDocument.SelectSingleNode("/response");
var responseStatusAttribute = responseElement.Attributes["status"];
var innerXml = responseElement.InnerXml;
var stringReader = new StringReader(innerXml);
// get the type
Type generatedType = responseStatusAttribute.InnerText == "ok"
? _typeGenerator.GenerateType(passedApiUrl)
: typeof(Error);
var serializer = new XmlSerializer(generatedType);
object deserialized = serializer.Deserialize(stringReader);
if (responseStatusAttribute.InnerText == "ok")
context.OperationResult = new OperationResult.OK(deserialized);
else
context.OperationResult = new OperationResult.BadRequest { ResponseResource = deserialized };
return PipelineContinuation.Continue;
}
示例10: LoadUpdateFileFromStream
public static UpdateFileInfo LoadUpdateFileFromStream(Stream xmlStream)
{
XmlSerializer serializer = new XmlSerializer(typeof(UpdateFileInfo));
XmlTextReader xmlTextReader = new XmlTextReader(xmlStream);
_updateFile = (UpdateFileInfo)serializer.Deserialize(xmlTextReader);
return _updateFile;
}
示例11: LoadUpdateFile
public static UpdateFileInfo LoadUpdateFile(string fileName)
{
XmlSerializer serializer = new XmlSerializer(typeof(UpdateFileInfo));
XmlTextReader xmlTextReader = new XmlTextReader(fileName);
_updateFile = (UpdateFileInfo)serializer.Deserialize(xmlTextReader);
return _updateFile;
}
示例12: Read
/// <summary>
/// Reads the PAP message from the specified stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
public static PapMessage Read(Stream stream)
{
XmlReaderSettings settings =
new XmlReaderSettings
{
CheckCharacters = true,
CloseInput = true,
ConformanceLevel = System.Xml.ConformanceLevel.Document,
DtdProcessing = DtdProcessing.Parse,
IgnoreComments = true,
ValidationType = ValidationType.DTD
};
XmlReader reader = XmlReader.Create(stream, settings);
try
{
// Deserialize the data
XmlSerializer serializer = new XmlSerializer(typeof(PapRoot));
object resultRoot = serializer.Deserialize(reader);
// Extract the response object from the appropriate root
PapMessage response = null;
if (resultRoot is PapRoot)
{
response = ((PapRoot)resultRoot).Response;
}
return response;
}
finally
{
reader.Close();
}
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
String xmlText = "";
Account acc = new Account();
acc.Address = "dsdsds";
acc.Country = "india";
acc.Id = "12312";
acc.Name = "pravin";
acc.Phone = "2323232";
acc.Sex = "male";
XmlSerializer ser = new XmlSerializer(acc.GetType());
StringWriter stringWriter = new StringWriter();
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter))
{
ser.Serialize(xmlWriter, acc);
}
xmlText = stringWriter.ToString();
UCTest1.SetText(xmlText);
}
示例14: ProcessRequest
protected override byte[] ProcessRequest(string path, Stream request,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
AssetBase asset;
XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
try
{
asset = (AssetBase)xs.Deserialize(request);
}
catch (Exception)
{
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}
string[] p = SplitParams(path);
if (p.Length > 0)
{
string id = p[0];
bool result = m_AssetService.UpdateContent(id, asset.Data);
xs = new XmlSerializer(typeof(bool));
return ServerUtils.SerializeResult(xs, result);
}
else
{
string id = m_AssetService.Store(asset);
xs = new XmlSerializer(typeof(string));
return ServerUtils.SerializeResult(xs, id);
}
}
示例15: ReadConfig
private static CassandraSharpConfig ReadConfig(XmlDocument xmlDoc)
{
XmlSerializer xmlSer = new XmlSerializer(typeof(CassandraSharpConfig));
//MiniXmlSerializer xmlSer = new MiniXmlSerializer(typeof(CassandraSharpConfig));
using (XmlReader xmlReader = new XmlNodeReader(xmlDoc))
return (CassandraSharpConfig)xmlSer.Deserialize(xmlReader);
}