本文整理匯總了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"));
}
示例2: SubstringBeforeBeginning
public static void SubstringBeforeBeginning()
{
var xmlDocument = new XmlDocument();
var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");
Assert.Throws<ArgumentOutOfRangeException>(() => cdataNode.Substring(-1, 1));
}
示例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;
}
示例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;
}
示例5: InsertDataBeyondEndOfCdataNodeBigNumber
public static void InsertDataBeyondEndOfCdataNodeBigNumber()
{
var xmlDocument = new XmlDocument();
var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("hello");
Assert.Throws<ArgumentOutOfRangeException>(() => cdataNode.InsertData(10, "hello "));
}
示例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);
}
示例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);
}
示例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;
}
示例9: CreateEmptyCdata
public static void CreateEmptyCdata()
{
var xmlDocument = new XmlDocument();
var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(String.Empty);
Assert.Equal(0, cdataNode.Length);
}
示例10: CreateCdata
public static void CreateCdata()
{
var xmlDocument = new XmlDocument();
var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");
Assert.Equal(5, cdataNode.Length);
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}