當前位置: 首頁>>代碼示例>>C#>>正文


C# Serialization.XmlSerializerNamespaces類代碼示例

本文整理匯總了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;
        }
開發者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


注:本文中的System.Xml.Serialization.XmlSerializerNamespaces類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。