当前位置: 首页>>代码示例>>C#>>正文


C# XmlDocument.CreateCDataSection方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.CreateCDataSection方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateCDataSection方法的具体用法?C# XmlDocument.CreateCDataSection怎么用?C# XmlDocument.CreateCDataSection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.CreateCDataSection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            //RoleEntity role = Authorization.isAuthorized(UserPrincipal.Current.SamAccountName, Request.RawUrl);

            //if (role == null)
            //{
            //    Response.Redirect("~/Authorization.aspx");
            //}

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("events.xml"));
            XmlNode node = xmlDoc.GetElementsByTagName("data")[0];
            node.RemoveAll();
            for (int i = 0; i < 2; i++)
            {
                XmlElement ev = xmlDoc.CreateElement("event");
                XmlAttribute atrXML = xmlDoc.CreateAttribute("id");
                atrXML.Value = new Random().Next().ToString();
                ev.SetAttributeNode(atrXML);
                //element.Attributes.Append(new XmlAttribute());


                XmlElement startDate = xmlDoc.CreateElement("start_date");
                var cdata = xmlDoc.CreateCDataSection("2013-05-23 00:00:00");
                startDate.AppendChild(cdata);

                ev.AppendChild(startDate);

                XmlElement endDate = xmlDoc.CreateElement("end_date");
                cdata = xmlDoc.CreateCDataSection("2013-05-24 00:00:00");
                endDate.AppendChild(cdata);

                ev.AppendChild(endDate);

                XmlElement text = xmlDoc.CreateElement("text");
                cdata = xmlDoc.CreateCDataSection("Test");
                text.AppendChild(cdata);

                ev.AppendChild(text);

                XmlElement details = xmlDoc.CreateElement("details");
                cdata = xmlDoc.CreateCDataSection("details");
                details.AppendChild(cdata);

                ev.AppendChild(details);

                node.AppendChild(ev);
            }

            xmlDoc.Save(Server.MapPath("events.xml"));
        }
开发者ID:GramozKrasniqi,项目名称:HRMS,代码行数:51,代码来源:WebFormEventTest.aspx.cs

示例2: SubstringBeforeBeginning

        public static void SubstringBeforeBeginning()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");

            Assert.Throws<ArgumentOutOfRangeException>(() => cdataNode.Substring(-1, 1));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:SubstringTests.cs

示例3: getXmlDoc

 private static XmlDocument getXmlDoc()
 {
     XmlDocument xmlDoc;
     try
     {
         xmlDoc = new XmlDocument();
         xmlDoc.Load(CONFIG_PATH);
     }
     catch
     {
         string dest = DateTime.Now.ToFileTime().ToString();
         if (File.Exists(CONFIG_PATH))
         {
             File.Move(CONFIG_PATH, dest);
             MessageBox.Show("配置已损坏!将使用默认配置\n原配置文件已被重命名为" + dest, "警告");
         }
         xmlDoc = new XmlDocument();
         xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
         XmlNode root = xmlDoc.CreateElement("config");
         XmlNode defaultPath = xmlDoc.CreateElement("path");
         XmlCDataSection cdata = xmlDoc.CreateCDataSection(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
         defaultPath.AppendChild(cdata);
         root.AppendChild(defaultPath);
         xmlDoc.AppendChild(root);
     }
     return xmlDoc;
 }
开发者ID:C4211,项目名称:GI,代码行数:27,代码来源:UserConfigUtil.cs

示例4: Serialize

        public void Serialize(TransportMessage transportMessage, Stream outputStream)
        {
            var xs = GetXmlSerializer();
            var doc = new XmlDocument();

            using (var tempstream = new MemoryStream())
            {
                xs.Serialize(tempstream, transportMessage);
                tempstream.Position = 0;

                doc.Load(tempstream);
            }

            if (transportMessage.Body != null && transportMessage.BodyStream == null)
            {
                transportMessage.BodyStream = new MemoryStream();
                this.messageSerializer.Serialize(transportMessage.Body, transportMessage.BodyStream);
            }

            // Reset the stream, so that we can read it back out as data
            transportMessage.BodyStream.Position = 0;

            var data = new StreamReader(transportMessage.BodyStream).ReadToEnd();
            var bodyElement = doc.CreateElement("Body");
            bodyElement.AppendChild(doc.CreateCDataSection(data));
            doc.DocumentElement.AppendChild(bodyElement);

            doc.Save(outputStream);
            outputStream.Position = 0;
        }
开发者ID:jdaigle,项目名称:CWServiceBus,代码行数:30,代码来源:XmlTransportMessageSerializer.cs

示例5: InsertDataBeyondEndOfCdataNodeBigNumber

        public static void InsertDataBeyondEndOfCdataNodeBigNumber()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("hello");

            Assert.Throws<ArgumentOutOfRangeException>(() => cdataNode.InsertData(10, "hello "));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:InsertDataTests.cs

示例6: Convert

        public void Convert(string inpath, string outpath)
        {
            if (String.IsNullOrEmpty(inpath))
            throw new ArgumentNullException("inpath");

             if (String.IsNullOrEmpty(outpath))
            throw new ArgumentNullException("outpath");

             XmlDocument doc = new XmlDocument();
             doc.Load(inpath);

             XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
             nsmgr.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/");

             XmlNodeList nodes = doc.SelectNodes("/rss/channel/item/content:encoded", nsmgr);

             foreach (XmlNode n in nodes)
             {
            string newText = ProcessBlogPost(n.InnerText);
            n.InnerText = null;
            n.AppendChild(doc.CreateCDataSection(newText));
             }

             doc.Save(outpath);
        }
开发者ID:asbjornu,项目名称:WordPressExportConverter,代码行数:25,代码来源:WordPressExportConverter.cs

示例7: ElementCreateAndAdd

 /// <summary>
 /// Crea un XmlElement.
 /// </summary>
 /// <param name="pdoc">XmlDocument que contendra el XmlElement.</param>
 /// <param name="pname">Nombre del XmlElement.</param>
 /// <param name="pvalue">Valor del XmlElement.</param>
 /// <returns>XmlElement</returns>
 public static XmlElement ElementCreateAndAdd(XmlDocument pdoc, string pname, string pvalue)
 {
     XmlElement elem = pdoc.CreateElement(pname);
     XmlCDataSection cdata = pdoc.CreateCDataSection(pvalue);
     elem.AppendChild(cdata);
     return (XmlElement) pdoc.AppendChild(elem);
 }
开发者ID:martinherr3,项目名称:medusa,代码行数:14,代码来源:Element.cs

示例8: CreateCDataElement

 private XmlElement CreateCDataElement(XmlDocument xDoc, string name, string value)
 {
     XmlElement xnode = xDoc.CreateElement(name);
     XmlCDataSection xdata = xDoc.CreateCDataSection(value);
     xnode.AppendChild(xdata);
     return xnode;
 }
开发者ID:davidsports,项目名称:Dnn.Platform,代码行数:7,代码来源:JournalControllerImpl.cs

示例9: CreateEmptyCdata

        public static void CreateEmptyCdata()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(String.Empty);

            Assert.Equal(0, cdataNode.Length);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:LengthTests.cs

示例10: CreateCdata

        public static void CreateCdata()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");

            Assert.Equal(5, cdataNode.Length);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:LengthTests.cs

示例11: CreateCDataSection

 public static XmlCDataSection CreateCDataSection(XmlDocument parentDoc, XmlElement parentElement,SPListItem item, string fieldName)
 {
     string valString = GetListItemValue(item, fieldName);
     XmlCDataSection newSection = parentDoc.CreateCDataSection(valString);
     parentElement.AppendChild(newSection);
     return newSection;
 }
开发者ID:infinitimods,项目名称:clif-sharepoint,代码行数:7,代码来源:Utility.cs

示例12: SerializeToXml

        public static void SerializeToXml(TransportMessage transportMessage, Stream stream)
        {
            var doc = new XmlDocument();

            using (var tempstream = new MemoryStream())
            {
                TransportMessageSerializer.Serialize(tempstream, transportMessage);
                tempstream.Position = 0;

                doc.Load(tempstream);
            }

            var data = transportMessage.Body.EncodeToUTF8WithoutIdentifier();

            var bodyElement = doc.CreateElement("Body");
            bodyElement.AppendChild(doc.CreateCDataSection(data));
            doc.DocumentElement.AppendChild(bodyElement);

            var headers = new SerializableDictionary<string, string>(transportMessage.Headers);

            var headerElement = doc.CreateElement("Headers");
            headerElement.InnerXml = headers.GetXml();
            doc.DocumentElement.AppendChild(headerElement);

            if (transportMessage.ReplyToAddress != null)
            {
                var replyToAddressElement = doc.CreateElement("ReplyToAddress");
                replyToAddressElement.InnerText = transportMessage.ReplyToAddress.ToString();
                doc.DocumentElement.AppendChild(replyToAddressElement);
            }

            doc.Save(stream);
            stream.Position = 0;
        }
开发者ID:rosieks,项目名称:NServiceBus.OracleAQ,代码行数:34,代码来源:TransportMessageMapper.cs

示例13: LengthOfCdataAfterDelete

        public static void LengthOfCdataAfterDelete()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");

            cdataNode.DeleteData(0, 1);
            Assert.Equal(4, cdataNode.Length);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:LengthTests.cs

示例14: InsertCDataNodeToDocumentNode

        public static void InsertCDataNodeToDocumentNode()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a/>");
            var cDataSection = xmlDocument.CreateCDataSection("data");

            Assert.Throws<InvalidOperationException>(() => xmlDocument.InsertBefore(cDataSection, null));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:InsertBeforeTests.cs

示例15: InsertDataInEmptyCdataNode

        public static void InsertDataInEmptyCdataNode()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(null);

            cdataNode.InsertData(0, "hello");

            Assert.Equal("hello", cdataNode.Data);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:InsertDataTests.cs


注:本文中的System.Xml.XmlDocument.CreateCDataSection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。