本文整理汇总了C#中System.Xml.Serialization.XmlSerializerNamespaces类的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializerNamespaces类的具体用法?C# XmlSerializerNamespaces怎么用?C# XmlSerializerNamespaces使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSerializerNamespaces类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlSerializerNamespaces类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例4: XmlConfigService
static XmlConfigService()
{
_xmlSerializer = new XmlSerializer(typeof(JobSchedulingData));
_xmlSerializerNamespaces = new XmlSerializerNamespaces();
_xmlSerializerNamespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
}
示例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();
}
}
}
示例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();
}
}
示例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"
)
};
}
示例8: RegistryObjectList
public RegistryObjectList()
{
xmlns = new XmlSerializerNamespaces(new []
{
new XmlQualifiedName("rim", Namespaces.Rim)
});
}
示例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");
}
示例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;
}
示例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;
}
}
示例12: komunikacja
/// <summary>
/// Kontruktor klasy
/// </summary>
public komunikacja()
{
names = new XmlSerializerNamespaces();
names.Add("", "");
log = "";
haslo = "";
}
示例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;
}
示例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));
}
示例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());
}