本文整理汇总了C#中System.Xml.Serialization.XmlSerializerNamespaces类的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializerNamespaces类的具体用法?C# XmlSerializerNamespaces怎么用?C# XmlSerializerNamespaces使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSerializerNamespaces类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlSerializerNamespaces类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: List2XML
/// <summary>
/// Metodo para serializar una Lista de objetos en un XML simple
/// </summary>
/// <param name="thelist"> la lista de tipo List<T> </param>
/// <returns></returns>
public static string List2XML(IList thelist)
{
string xml = "";
try
{
XmlSerializer xmlSer = new XmlSerializer(thelist.GetType());
StringWriterWithEncoding sWriter = new StringWriterWithEncoding(Encoding.UTF8);
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
xsn.Add(String.Empty, "");
xmlSer.Serialize(sWriter, thelist, xsn);
xml = sWriter.ToString();
}
catch (Exception e)
{
}
return xml;
}
开发者ID:julianobarbosa,项目名称:integradesigner,代码行数:35,代码来源:XMLObjectConverter.cs
示例2: XmlSerializationOptions
public XmlSerializationOptions(
XmlSerializerNamespaces namespaces = null,
Encoding encoding = null,
bool shouldEncryptRootObject = false,
string defaultNamespace = null,
bool shouldIndent = false,
string rootElementName = null,
bool shouldAlwaysEmitTypes = false,
bool shouldRedact = true,
bool shouldEncrypt = true,
bool treatEmptyElementAsString = false,
bool emitNil = false,
IEncryptionMechanism encryptionMechanism = null,
object encryptKey = null,
bool ShouldIgnoreCaseForEnum = false)
{
_namespaces = namespaces ?? new XmlSerializerNamespaces();
_encoding = encoding ?? Encoding.UTF8;
_shouldEncryptRootObject = shouldEncryptRootObject;
_defaultNamespace = defaultNamespace;
_shouldIndent = shouldIndent;
_rootElementName = rootElementName;
_shouldAlwaysEmitTypes = shouldAlwaysEmitTypes;
_shouldRedact = shouldRedact;
_shouldEncrypt = shouldEncrypt;
_extraTypes = null;
_treatEmptyElementAsString = treatEmptyElementAsString;
_emitNil = emitNil;
_encryptionMechanism = encryptionMechanism;
_encryptKey = encryptKey;
_shouldIgnoreCaseForEnum = ShouldIgnoreCaseForEnum;
}
开发者ID:ahismaeel,项目名称:XSerializer,代码行数:32,代码来源:XmlSerializationOptions.cs
示例3: 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;
}
开发者ID:valery-shinkevich,项目名称:sooda,代码行数:30,代码来源:CommandGenFullSchema.cs
示例4: XmlConfigService
static XmlConfigService()
{
_xmlSerializer = new XmlSerializer(typeof(JobSchedulingData));
_xmlSerializerNamespaces = new XmlSerializerNamespaces();
_xmlSerializerNamespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
}
开发者ID:modulexcite,项目名称:QuartzHelper,代码行数:7,代码来源:XmlConfigService.cs
示例5: createSerializedXmlFileFromObject
// Similar code exist in O2.DotNetWrappers.DotNet.Serialize
public static bool createSerializedXmlFileFromObject(Object oObjectToProcess, String sTargetFile, Type[] extraTypes)
{
FileStream fileStream = null;
try
{
var xnsXmlSerializerNamespaces = new XmlSerializerNamespaces();
xnsXmlSerializerNamespaces.Add("", "");
var xsXmlSerializer = (extraTypes != null)
? new XmlSerializer(oObjectToProcess.GetType(), extraTypes)
: new XmlSerializer(oObjectToProcess.GetType());
fileStream = new FileStream(sTargetFile, FileMode.Create);
xsXmlSerializer.Serialize(fileStream, oObjectToProcess, xnsXmlSerializerNamespaces);
//fileStream.Close();
return true;
}
catch (Exception ex)
{
DI.log.ex(ex, "In createSerializedXmlStringFromObject");
return false;
}
finally
{
if (fileStream != null)
{
fileStream.Close();
}
}
}
开发者ID:pusp,项目名称:o2platform,代码行数:33,代码来源:O2Kernel_Serialize.cs
示例6: Save
public bool Save(MySettings settings)
{
StreamWriter sw = null;
try
{
//now global: XmlSerializer xs = new XmlSerializer(typeof(MySettings));
//omit xmlns:xsi from xml output
//Create our own namespaces for the output
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
//Add an empty namespace and empty value
ns.Add("", "");
sw = new StreamWriter(settingsFile);
xs.Serialize(sw, settings, ns);
return true;
}
catch (Exception ex)
{
utils.helpers.addExceptionLog(ex.Message);
return false;
}
finally
{
if (sw != null)
sw.Close();
}
}
开发者ID:hjgode,项目名称:mail_grabber,代码行数:26,代码来源:mysettings.cs
示例7: Post
public async Task<HttpResponseMessage> Post() {
TextMessage recievedMessage;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(TextMessage));
Stream stream = await Request.Content.ReadAsStreamAsync();
using (var reader = new StreamReader(stream)) {
recievedMessage = (TextMessage)xmlSerializer.Deserialize(reader);
}
TextMessage sendingMessage = new TextMessage() {
ToUserName = recievedMessage.FromUserName,
FromUserName = recievedMessage.ToUserName,
CreateTime = ConvertToUnixTimestamp(DateTime.Now).ToString(),
Content = recievedMessage.Content
};
Trace.TraceInformation(Request.Headers.Accept.ToString());
string messageStr = string.Empty;
using (StringWriter textWriter = new StringWriter()) {
var xns = new XmlSerializerNamespaces();
xns.Add(string.Empty, string.Empty);
xmlSerializer.Serialize(textWriter, sendingMessage, xns);
messageStr = textWriter.ToString();
}
return new HttpResponseMessage() {
Content = new StringContent(
messageStr,
Encoding.UTF8,
"text/html"
)
};
}
开发者ID:gerrardspirit,项目名称:WEIXIN_TEST,代码行数:35,代码来源:WeChatController.cs
示例8: RegistryObjectList
public RegistryObjectList()
{
xmlns = new XmlSerializerNamespaces(new []
{
new XmlQualifiedName("rim", Namespaces.Rim)
});
}
开发者ID:haboustak,项目名称:XdsKit,代码行数:7,代码来源:RegistryObjectList.cs
示例9: TestMethod1
public void TestMethod1()
{
XmlSerializer xsSubmit = new XmlSerializer(typeof(TestSection));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
var mySection = new TestSection();
mySection.myDecimal = 2.15M;
mySection.myInt = 215;
mySection.myString = "215";
using (StringWriter sww = new StringWriter())
using (XmlWriter writer = XmlWriter.Create(sww, new XmlWriterSettings() { OmitXmlDeclaration = true }))
{
xsSubmit.Serialize(writer, mySection, ns);
var xml = sww.ToString();
}
// Save Xml
string configutaionFilePath = Environment.CurrentDirectory;
var Xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<configuration>
<configSections>
</configSections>
</configuration>
";
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(Xml);
xdoc.Save(configutaionFilePath + @"\config.xml");
}
开发者ID:kanpinar,项目名称:test_again,代码行数:30,代码来源:UnitTest1.cs
示例10: GetTax
// This actually calls the service to perform the tax calculation, and returns the calculation result.
public async Task<GetTaxResult> GetTax(GetTaxRequest req)
{
// Convert the request to XML
XmlSerializerNamespaces namesp = new XmlSerializerNamespaces();
namesp.Add(string.Empty, string.Empty);
XmlWriterSettings settings = new XmlWriterSettings {OmitXmlDeclaration = true};
XmlSerializer x = new XmlSerializer(req.GetType());
StringBuilder sb = new StringBuilder();
x.Serialize(XmlWriter.Create(sb, settings), req, namesp);
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
// Call the service
Uri address = new Uri(_svcUrl + "tax/get");
var request = HttpHelper.CreateRequest(address, _accountNumber, _license);
request.Method = "POST";
request.ContentType = "text/xml";
//request.ContentLength = sb.Length;
Stream newStream = await request.GetRequestStreamAsync();
newStream.Write(Encoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length);
GetTaxResult result = new GetTaxResult();
try
{
WebResponse response = await request.GetResponseAsync();
XmlSerializer r = new XmlSerializer(result.GetType());
result = (GetTaxResult) r.Deserialize(response.GetResponseStream());
}
catch (WebException ex)
{
XmlSerializer r = new XmlSerializer(result.GetType());
result = (GetTaxResult) r.Deserialize(((HttpWebResponse) ex.Response).GetResponseStream());
}
return result;
}
开发者ID:multiarc,项目名称:AvaTax-Calc-REST-csharp,代码行数:36,代码来源:TaxService.cs
示例11: Cancelar
public string Cancelar()
{
try
{
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
nameSpaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nameSpaces.Add("tipos", "http://localhost:8080/WsNFe2/tp");
nameSpaces.Add("ns1", "http://localhost:8080/WsNFe2/lote");
string sPath = Pastas.PROTOCOLOS + "\\REQ_CANC_LOTE_" + objCancelamento.lote.Id.Replace("Lote:", "") + ".xml";
if (File.Exists(sPath))
{
File.Delete(sPath);
}
string sXmlSerializer = null;
XmlSerializer xs = new XmlSerializer(typeof(ReqCancelamentoNFSe));
MemoryStream memory = new MemoryStream();
XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
xs.Serialize(xmltext, objCancelamento, nameSpaces);
UTF8Encoding encoding = new UTF8Encoding();
sXmlSerializer = encoding.GetString(memory.ToArray());
sXmlSerializer = sXmlSerializer.Substring(1);
belAssinaXml Assinatura = new belAssinaXml();
sXmlSerializer = Assinatura.ConfigurarArquivo(sXmlSerializer, "Lote", Acesso.cert_NFs);
//SerializeClassToXml.SerializeClasse<ReqCancelamentoNFSe>(objCancelamento, sPath, nameSpaces);
XmlDocument xmlConsulta = new XmlDocument();
xmlConsulta.LoadXml(sXmlSerializer);
xmlConsulta.Save(sPath);
belValidaXml.ValidarXml("http://localhost:8080/WsNFe2/lote", Pastas.SCHEMA_NFSE_DSF + "\\ReqCancelamentoNFSe.xsd", sPath);
string sPathRetConsultaCanc = Pastas.PROTOCOLOS + "\\Ret_CANC_LOTE_" + objCancelamento.lote.Id.Replace("Lote:", "") + ".xml";
HLP.GeraXml.WebService.NFSE_Campinas.LoteRpsService lt = new WebService.NFSE_Campinas.LoteRpsService();
string sRetornoLote = lt.cancelar(xmlConsulta.InnerXml);
xmlConsulta = new XmlDocument();
xmlConsulta.LoadXml(sRetornoLote);
xmlConsulta.Save(sPathRetConsultaCanc);
// sPathRetConsultaCanc = @"D:\Ret_CANC_LOTE_2805131157.xml";
RetornoCancelamentoNFSe objretorno = SerializeClassToXml.DeserializeClasse<RetornoCancelamentoNFSe>(sPathRetConsultaCanc);
string sMessageRetorno = TrataRetornoCancelamento(objretorno);
return sMessageRetorno;
}
catch (Exception ex)
{
throw ex;
}
}
开发者ID:dramosti,项目名称:GeraXml_3.0,代码行数:60,代码来源:belCancelamentoDSF.cs
示例12: komunikacja
/// <summary>
/// Kontruktor klasy
/// </summary>
public komunikacja()
{
names = new XmlSerializerNamespaces();
names.Add("", "");
log = "";
haslo = "";
}
开发者ID:kitpz2,项目名称:grupappz,代码行数:10,代码来源:komunikacja.cs
示例13: CreateAppManifest
public static PackagePart CreateAppManifest(this Package package, Guid productId, Guid identifier, string title, string launchUrl) {
AppManifest o = new AppManifest() {
Name = Guid.NewGuid().ToString(),
ProductID = productId,
Version = "1.0.0.0",
SharePointMinVersion = "15.0.0.0",
Properties = new AppManifest.AppProperties() {
Title = title,
LaunchUrl = launchUrl
},
Principal = new AppManifest.AppPrincipal {
RemoteWebApplication = new AppManifest.RemoteWebApplication {
ClientId = identifier
}
}
};
Uri partUri = new Uri("/AppManifest.xml", UriKind.Relative);
string contentType = "text/xml";
PackagePart part = package.CreatePart(partUri, contentType);
using (Stream stream = part.GetStream(FileMode.Create, FileAccess.Write))
using (XmlWriter writer = XmlTextWriter.Create(stream)) {
XmlSerializer serializer = new XmlSerializer(typeof(AppManifest));
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("", "http://schemas.microsoft.com/sharepoint/2012/app/manifest");
serializer.Serialize(writer, o, namespaces);
}
return part;
}
开发者ID:RunLola,项目名称:Practices.SharePoint,代码行数:29,代码来源:AppPartFactory.cs
示例14: ForTypesWithoutInterfacesCustomSerializerSerializesTheSameAsDefaultSerializer
public void ForTypesWithoutInterfacesCustomSerializerSerializesTheSameAsDefaultSerializer(
object instance,
string defaultNamespace,
Type[] extraTypes,
string rootElementName,
Encoding encoding,
Formatting formatting,
XmlSerializerNamespaces namespaces)
{
var defaultSerializer =
(IXmlSerializer)Activator.CreateInstance(
typeof(DefaultSerializer<>).MakeGenericType(instance.GetType()),
defaultNamespace,
extraTypes,
rootElementName);
var customSerializer =
(IXmlSerializer)Activator.CreateInstance(
typeof(CustomSerializer<>).MakeGenericType(instance.GetType()),
defaultNamespace,
extraTypes,
rootElementName);
var defaultXml = defaultSerializer.SerializeObject(instance, namespaces, encoding, formatting);
var customXml = customSerializer.SerializeObject(instance, namespaces, encoding, formatting);
Console.WriteLine("Default XML:");
Console.WriteLine(defaultXml);
Console.WriteLine();
Console.WriteLine("Custom XML:");
Console.WriteLine(customXml);
Assert.That(customXml, Is.EqualTo(defaultXml));
}
开发者ID:korzy1bj,项目名称:XSerializer,代码行数:33,代码来源:SerializationTests.cs
示例15: getRequestContent
public byte[] getRequestContent( string doctype, string root, Type type, object obj)
{
XmlSerializer serializer = null;
if (root == null)
{
//... root element will be the object type name
serializer = new XmlSerializer(type);
}
else
{
//... root element set explicitely
var xattribs = new XmlAttributes();
var xroot = new XmlRootAttribute(root);
xattribs.XmlRoot = xroot;
var xoverrides = new XmlAttributeOverrides();
xoverrides.Add(type, xattribs);
serializer = new XmlSerializer(type, xoverrides);
}
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = false;
settings.OmitXmlDeclaration = false;
settings.Encoding = new UTF8Encoding(false/*no BOM*/, true/*throw if input illegal*/);
XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces();
xmlNameSpace.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlNameSpace.Add("noNamespaceSchemaLocation", m_schemadir + "/" + doctype + "." + m_schemaext);
StringWriter sw = new StringWriter();
XmlWriter xw = XmlWriter.Create( sw, settings);
xw.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
serializer.Serialize(xw, obj, xmlNameSpace);
return settings.Encoding.GetBytes( sw.ToString());
}
开发者ID:ProjectTegano,项目名称:Tegano,代码行数:35,代码来源:Serializer.cs
示例16: Serialize
public static void Serialize(Stream stream, object value) {
var ns = new XmlSerializerNamespaces();
ns.Add("", "");
var serializer = new XmlSerializer(value.GetType(), "");
using (var xml = XmlWriter.Create(stream, XmlWriterSettings))
serializer.Serialize(xml, value, ns);
}
开发者ID:drunkcod,项目名称:Xlnt.Stuff,代码行数:7,代码来源:XmlResult.cs
示例17: Serialize
//private readonly Utilities sUtilities = Singleton<Utilities>.Instance;
/// <summary>
/// Serializes the current instance and returns the result as a <see cref="string"/>
/// <para>Should be used with XML serialization only.</para>
/// </summary>
/// <returns>The serialized instance.</returns>
public string Serialize()
{
//if(!sPlatform.IsLinux)
// Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>()));
string data;
try
{
using(var ms = new MemoryStream())
{
var serializer = new XmlSerializer(GetType());
var nss = new XmlSerializerNamespaces();
nss.Add(string.Empty, string.Empty);
serializer.Serialize(ms, this, nss);
using(var reader = new StreamReader(ms))
{
data = reader.ReadToEnd();
}
}
}
catch(InvalidOperationException x)
{
throw new WolframException(sLConsole.GetString("Error during serialization"), x);
}
if(string.IsNullOrEmpty(data))
throw new WolframException(string.Format(sLConsole.GetString("Error while serializing instance! Type: {0}"), GetType().FullName));
return data;
}
开发者ID:Schumix,项目名称:Schumix2,代码行数:38,代码来源:XmlSerialized.cs
示例18: createSerializedXmlStringFromObject
public static String createSerializedXmlStringFromObject(Object oObjectToProcess , Type[] extraTypes)
{
if (oObjectToProcess == null)
DI.log.error("in createSerializedXmlStringFromObject: oObjectToProcess == null");
else
{
try
{
/*// handle cases file names are bigger than 220
if (sTargetFile.Length > 220)
{
sTargetFile = sTargetFile.Substring(0, 200) + ".xml";
DI.log.error("sTargetFile.Length was > 200, so renamig it to: {0}", sTargetFile);
}*/
var xnsXmlSerializerNamespaces = new XmlSerializerNamespaces();
xnsXmlSerializerNamespaces.Add("", "");
var xsXmlSerializer = (extraTypes != null)
? new XmlSerializer(oObjectToProcess.GetType(), extraTypes)
: new XmlSerializer(oObjectToProcess.GetType());
var memoryStream = new MemoryStream();
xsXmlSerializer.Serialize(memoryStream, oObjectToProcess, xnsXmlSerializerNamespaces);
return Encoding.ASCII.GetString(memoryStream.ToArray());
}
catch (Exception ex)
{
DI.log.ex(ex,"In createSerializedXmlStringFromObject");
}
}
return "";
}
开发者ID:pusp,项目名称:o2platform,代码行数:31,代码来源:Serialize.cs
示例19: getRequestContent
public static byte[] getRequestContent(string doctype, string root, Type type, object obj)
{
var xattribs = new XmlAttributes();
var xroot = new XmlRootAttribute(root);
xattribs.XmlRoot = xroot;
var xoverrides = new XmlAttributeOverrides();
//... have to use XmlAttributeOverrides because .NET insists on the object name as root element name otherwise ([XmlRoot(..)] has no effect)
xoverrides.Add(type, xattribs);
XmlSerializer serializer = new XmlSerializer(type, xoverrides);
StringWriter sw = new StringWriter();
XmlWriterSettings wsettings = new XmlWriterSettings();
wsettings.OmitXmlDeclaration = false;
wsettings.Encoding = new UTF8Encoding();
XmlWriter xw = XmlWriter.Create(sw, wsettings);
xw.WriteProcessingInstruction("xml", "version='1.0' standalone='no'");
//... have to write header by hand (OmitXmlDeclaration=false has no effect)
xw.WriteDocType(root, null, doctype + ".sfrm", null);
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
//... trick to avoid printing of xmlns:xsi xmlns:xsd attributes of the root element
serializer.Serialize(xw, obj, ns);
return sw.ToArray();
}
开发者ID:ProjectTegano,项目名称:Tegano,代码行数:26,代码来源:Serializer.cs
示例20: SaveDelta
public static void SaveDelta(Delta delta, string file)
{
var ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");
var serializer = new XmlSerializer(typeof(Delta));
var list = new List<ImportObject>();
foreach (var obj in delta.Objects.Where(x => x.NeedsInclude()))
{
var newObj = new ImportObject();
newObj.SourceObjectIdentifier = obj.SourceObjectIdentifier;
newObj.TargetObjectIdentifier = obj.TargetObjectIdentifier;
newObj.ObjectType = obj.ObjectType;
newObj.State = obj.State;
newObj.Changes = obj.Changes != null ? obj.Changes.Where(x => x.IsIncluded).ToArray() : null;
newObj.AnchorPairs = obj.AnchorPairs;
list.Add(newObj);
}
var newDelta = new Delta();
newDelta.Objects = list.ToArray();
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.Indent = true;
using (var w = XmlWriter.Create(file, settings))
serializer.Serialize(w, newDelta, ns);
}
开发者ID:bdesmond,项目名称:FIMDelta,代码行数:30,代码来源:DeltaParser.cs
注:本文中的System.Xml.Serialization.XmlSerializerNamespaces类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论