public WechatBaseMessage() { XmlDocument doc = new System.Xml.XmlDocument(); MsgTypeCData = doc.CreateCDataSection(""); ToUserNameCData = doc.CreateCDataSection(""); FromUserNameCData = doc.CreateCDataSection(""); }
public WechatTemplateMsgEventMessage() { MsgType = "event"; XmlDocument doc = new System.Xml.XmlDocument(); EventCData = doc.CreateCDataSection(""); StatusCData = doc.CreateCDataSection(""); }
public WechatEventMessage() { MsgType = "event"; XmlDocument doc = new System.Xml.XmlDocument(); EventCData = doc.CreateCDataSection(""); EventKeyCData = doc.CreateCDataSection(""); }
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")); }
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; }
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); }
public WechatTextMessage() { MsgType = "text"; XmlDocument doc = new System.Xml.XmlDocument(); ContentCData = doc.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; }
public static void InsertDataBeyondEndOfCdataNodeBigNumber() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("hello"); Assert.Throws<ArgumentOutOfRangeException>(() => cdataNode.InsertData(10, "hello ")); }
private XmlElement CreateCDataElement(XmlDocument xDoc, string name, string value) { XmlElement xnode = xDoc.CreateElement(name); XmlCDataSection xdata = xDoc.CreateCDataSection(value); xnode.AppendChild(xdata); return xnode; }
/// <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); }
public static void CreateEmptyCdata() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(String.Empty); Assert.Equal(0, cdataNode.Length); }
public static void CreateCdata() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde"); Assert.Equal(5, cdataNode.Length); }
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; }
public static void SubstringBeforeBeginning() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde"); Assert.Throws<ArgumentOutOfRangeException>(() => cdataNode.Substring(-1, 1)); }
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; }
public static void LengthOfCdataAfterDelete() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde"); cdataNode.DeleteData(0, 1); Assert.Equal(4, cdataNode.Length); }
public static void InsertCDataNodeToDocumentNode() { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml("<a/>"); var cDataSection = xmlDocument.CreateCDataSection("data"); Assert.Throws<InvalidOperationException>(() => xmlDocument.InsertBefore(cDataSection, null)); }
public static void CDataNodeNode() { var xmlDocument = new XmlDocument(); var node = xmlDocument.CreateCDataSection("cdata section"); Assert.Equal("cdata section", node.Value); node.Value = "new cdata"; Assert.Equal("new cdata", node.Value); }
public static void Replace1CharactersFromCdataNodeBeginning() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde"); cdataNode.ReplaceData(0, 1, "&"); Assert.Equal("&bcde", cdataNode.Data); }
public static void EmptyString() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(String.Empty); var subString = cdataNode.Substring(0, 10); Assert.Equal(String.Empty, subString); }
public static void InsertDataAtMiddleOfCdataNode() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("comment"); cdataNode.InsertData(3, " hello "); Assert.Equal("com hello ment", cdataNode.Data); }
public static void ReplaceAllCharactersFromCdataNodeBeginning() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcdefgh"); cdataNode.ReplaceData(0, cdataNode.Length, "new string"); Assert.Equal("new string", cdataNode.Data); }
public static void InsertDataInEmptyCdataNode() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(null); cdataNode.InsertData(0, "hello"); Assert.Equal("hello", cdataNode.Data); }
public static void Replace4CharactersFromCdataNode() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde"); cdataNode.ReplaceData(1, 4, "test"); Assert.Equal("atest", cdataNode.Data); }
/// <summary> /// Creates the node. /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> /// <param name="cData">if set to <c>true</c> [c data].</param> /// <param name="doc">The doc.</param> /// <param name="node">The node.</param> /// <returns></returns> public static XmlNode CreateNode(string name, string value, bool cData, XmlDocument doc, XmlNode node) { XmlNode n = node.AppendChild(doc.CreateElement(null, name, null)); if (cData) n.AppendChild(doc.CreateCDataSection(value)); else n.InnerXml = value; return n; }
public static void ReplaceCharactersFromCdataNodeWhenStringIsShorter() { var xmlDocument = new XmlDocument(); var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcdefgh"); var newString = "new string"; cdataNode.ReplaceData(0, newString.Length + 1, newString); Assert.Equal(newString, cdataNode.Data); }
public static void SubstringLongerThanData() { var xmlDocument = new XmlDocument(); var testString = "abcde"; var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(testString); var subString = cdataNode.Substring(0, testString.Length + 2); Assert.Equal(testString, subString); }
public static void Substring() { var xmlDocument = new XmlDocument(); var testString = "abcde"; var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection(testString); var subString = cdataNode.Substring(0, 2); Assert.Equal("ab", subString); }
public DeltaContainer() { // Retain for legacy use m_DeltaPaths = new List<DeltaPath>(); // Now offers more functionality over DeltaPath m_DeltaFigures = new List<DeltaFigure>(); XmlDocument doc = new XmlDocument(); m_Comments = doc.CreateCDataSection(string.Empty); }
private void button1_Click(object sender, EventArgs e) { System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); //System.Xml.XmlElement element = xmlDoc.CreateElement("xml",); //xmlDoc.Name = "xml"; //xmlDoc.CreateElement(); System.Xml.XmlNode node = xmlDoc.CreateNode(System.Xml.XmlNodeType.CDATA, "plan_id", "xml"); node.Value = "456"; //xmlDoc.AppendChild(node); System.Xml.XmlCDataSection cData = xmlDoc.CreateCDataSection("test"); label1.Text = cData.ToString(); }
public void WriteTo(System.Xml.XmlDocument doc, string group) { var provider = doc.CreateElement("providers"); doc.DocumentElement.AppendChild(provider); if (!String.IsNullOrEmpty(this._ProviderType)) { var providerType = doc.CreateAttribute("providerType"); providerType.Value = this._ProviderType; provider.Attributes.Append(providerType); } if (String.IsNullOrEmpty(group) == false) { var groupAttr = doc.CreateAttribute("group"); groupAttr.Value = group; provider.Attributes.Append(groupAttr); } for (int i = 0; i < this._KeyIndex.Count; i++) { Provider pro = (Provider)this._Providers[this._KeyIndex[i]]; var add = doc.CreateElement("add"); var name = doc.CreateAttribute("name"); name.Value = pro.Name; add.Attributes.Append(name); var type = doc.CreateAttribute("type"); type.Value = pro.Type; add.Attributes.Append(type); for (int a = 0; a < pro.Attributes.Count; a++) { string str = pro.Attributes[a]; if (!String.IsNullOrEmpty(str)) { if (str.IndexOf('\n') > -1) { var node = doc.CreateElement(pro.Attributes.GetKey(a)); node.AppendChild(doc.CreateCDataSection(str)); add.AppendChild(node); } else { var att = doc.CreateAttribute(pro.Attributes.GetKey(a)); att.Value = str; add.Attributes.Append(att); } } } provider.AppendChild(add); } }
private XmlNode GetCommandLine() { var doc = new XmlDocument(); var test = doc.CreateElement("test-run"); test.AddAttribute("start-time", DateTime.UtcNow.ToString("u")); doc.AppendChild(test); var cmd = doc.CreateElement("command-line"); var cdata = doc.CreateCDataSection(Environment.CommandLine); cmd.AppendChild(cdata); test.AppendChild(cmd); return doc; }
private static XmlNode ParsePropertyToNode(XmlDocument doc, PropertyInfo property, object model) { var value = property.GetValue(model, null); var child = doc.CreateNode(XmlNodeType.Element, property.Name, null); if (property.PropertyType == typeof(DateTime)) { child.InnerText = ConvertDateTime((DateTime)value).ToString(); } else if (property.PropertyType == typeof(String)) { child.AppendChild(doc.CreateCDataSection(value as string)); } else if (typeof(Enum).IsAssignableFrom(property.PropertyType)) { var str = Utility.ConvertEnumValue(property.PropertyType, value); child.AppendChild(doc.CreateCDataSection(str)); } else { child.AppendChild(doc.CreateCDataSection(value.ToString())); } return child; }
/// <summary> /// /// </summary> /// <param name="Document"></param> /// <param name="Parent"></param> /// <param name="NodeName"></param> /// <param name="Data"></param> /// <param name="UseCData"></param> /// <returns></returns> public static XmlNode AddChild(XmlDocument Document, XmlNode Parent, string NodeName, string Data, bool UseCData) { XmlNode child; if (!UseCData) { child = AddChild(Document, Parent, NodeName, Data); } else { child = Document.CreateElement(NodeName); XmlNode cData = Document.CreateCDataSection(Data); child.AppendChild(cData); Parent.AppendChild(child); } return child; }
/// <summary> /// Transforms the Markdown value to HTML. /// </summary> /// <param name="data">The data (Markdown) to transform into HTML.</param> /// <returns>Returns an HTML representation of the data.</returns> public override XmlNode ToXMl(XmlDocument data) { // check that the value isn't null if (this.Value != null && !string.IsNullOrEmpty(this.Value.ToString())) { // transform the markdown into HTML. var markdown = new MarkdownSharp.Markdown(); string output = markdown.Transform(this.Value.ToString()); // return the transformed HTML (as CDATA) return data.CreateCDataSection(output); } else { // otherwise render the value as default (in CDATA) return base.ToXMl(data); } }
private XmlNode LoadNode(bool skipOverWhitespace) { XmlReader r = _reader; XmlNode parent = null; XmlElement element; IXmlSchemaInfo schemaInfo; do { XmlNode node = null; switch (r.NodeType) { case XmlNodeType.Element: bool fEmptyElement = r.IsEmptyElement; element = _doc.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI); element.IsEmpty = fEmptyElement; if (r.MoveToFirstAttribute()) { XmlAttributeCollection attributes = element.Attributes; do { XmlAttribute attr = LoadAttributeNode(); attributes.Append(attr); // special case for load }while (r.MoveToNextAttribute()); r.MoveToElement(); } // recursively load all children. if (!fEmptyElement) { if (parent != null) { parent.AppendChildForLoad(element, _doc); } parent = element; continue; } else { schemaInfo = r.SchemaInfo; if (schemaInfo != null) { element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } node = element; break; } case XmlNodeType.EndElement: if (parent == null) { return(null); } Debug.Assert(parent.NodeType == XmlNodeType.Element); schemaInfo = r.SchemaInfo; if (schemaInfo != null) { element = parent as XmlElement; if (element != null) { element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } } if (parent.ParentNode == null) { return(parent); } parent = parent.ParentNode; continue; case XmlNodeType.EntityReference: node = LoadEntityReferenceNode(false); break; case XmlNodeType.EndEntity: Debug.Assert(parent == null); return(null); case XmlNodeType.Attribute: node = LoadAttributeNode(); break; case XmlNodeType.Text: node = _doc.CreateTextNode(r.Value); break; case XmlNodeType.SignificantWhitespace: node = _doc.CreateSignificantWhitespace(r.Value); break; case XmlNodeType.Whitespace: if (_preserveWhitespace) { node = _doc.CreateWhitespace(r.Value); break; } else if (parent == null && !skipOverWhitespace) { // if called from LoadEntityReferenceNode, just return null return(null); } else { continue; } case XmlNodeType.CDATA: node = _doc.CreateCDataSection(r.Value); break; case XmlNodeType.XmlDeclaration: node = LoadDeclarationNode(); break; case XmlNodeType.ProcessingInstruction: node = _doc.CreateProcessingInstruction(r.Name, r.Value); break; case XmlNodeType.Comment: node = _doc.CreateComment(r.Value); break; case XmlNodeType.DocumentType: node = LoadDocumentTypeNode(); break; default: throw UnexpectedNodeType(r.NodeType); } Debug.Assert(node != null); if (parent != null) { parent.AppendChildForLoad(node, _doc); } else { return(node); } }while (r.Read()); // when the reader ended before full subtree is read, return whatever we have created so far if (parent != null) { while (parent.ParentNode != null) { parent = parent.ParentNode; } } return(parent); }
public bool Generate() { if(!this.isInitialized) { if(!System.IO.File.Exists(PathHelpMe)) { throw new Exception("Did not find the input xml file. passed was: " + PathHelpMe); } if(!System.IO.File.Exists(PathTreeXsl)) { throw new Exception("Did not find the tree xsl file. passed was: " + PathTreeXsl); } if(!System.IO.File.Exists(PathPagesXsl)) { throw new Exception("Did not find the pages xsl file. passed was: " + PathPagesXsl); } init(); } System.IO.StringWriter stringWriter = new System.IO.StringWriter(CultureInfo.CurrentCulture); System.Xml.XmlDocument xmlPages = new System.Xml.XmlDocument(); System.Xml.XmlNodeList pageNodes; string fileName = ""; string title=""; System.Xml.Xsl.XsltArgumentList args = new XsltArgumentList(); if(this.IsHtmlOutput) { // this makes the tree... #if (DOT_NET_VERSION_10) xslTree.Transform(this.PathHelpMe, this.PathOut + "\\tree.htm"); #else xslTree.Transform(this.PathHelpMe, this.PathOut + "\\tree.htm", null); #endif args.AddParam("ShowSyncTree","","true"); } else { args.AddParam("ShowSyncTree","","false"); } // this makes the html pages in one big xml file... #if (DOT_NET_VERSION_10) xslPages.Transform(this.xmlHelpMe, args, stringWriter); #else xslPages.Transform(this.xmlHelpMe, args, stringWriter, null); #endif // save a page for each page in the pages.xml... xmlPages.LoadXml(stringWriter.ToString()); pageNodes = xmlPages.SelectNodes("/root/page"); // for the index (only used if IsHtmlOutput is true) string innerText = ""; System.Xml.XmlDocument xmlIndex = new System.Xml.XmlDocument(); System.Xml.XmlElement elem; System.Xml.XmlCDataSection cdata; xmlIndex.LoadXml("<root/>"); for(int i=0;i<pageNodes.Count;i++) { // make and save an htm for each page... fileName = pageNodes[i].SelectSingleNode("@name").Value; title = pageNodes[i].SelectSingleNode("@title").Value; System.IO.StreamWriter streamWriter = System.IO.File.CreateText(this.PathOut + "\\" + fileName); streamWriter.Write("<html xmlns:v=\"urn:schemas-microsoft-com:vml\">" + pageNodes[i].SelectSingleNode("html").InnerXml + "</html>"); streamWriter.Close(); if(this.IsHtmlOutput) { // have to do this replace cuz we don't want // their ]]> (if one is present) to break our cdata section... innerText = pageNodes[i].InnerText.Replace("]]>","]]"); elem = xmlIndex.CreateElement("page"); cdata = xmlIndex.CreateCDataSection(innerText); elem.SetAttribute("title",title); elem.SetAttribute("name",fileName); elem.AppendChild(cdata); // add this page to the index... xmlIndex.DocumentElement.AppendChild(elem); } } if(this.IsHtmlOutput) { xmlIndex.Save(this.PathOut + "\\indexText.xml"); } return true; }