本文整理汇总了C#中XmlDocument.CreateTextNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateTextNode方法的具体用法?C# XmlDocument.CreateTextNode怎么用?C# XmlDocument.CreateTextNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateTextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
String connect = "Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source=c:\booksharp\gittleman\ch15\Sales.mdb";
OleDbConnection con = new OleDbConnection(connect);
con.Open();
Console.WriteLine
("Made the connection to the Sales database");
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM Customer";
OleDbDataReader reader = cmd.ExecuteReader();
XmlDocument document = new XmlDocument();
XmlElement customers = document.CreateElement("customers");
document.AppendChild(customers);
while (reader.Read()) {
XmlElement customer = document.CreateElement("customer");
customers.AppendChild(customer);
XmlElement name = document.CreateElement("name");
customer.AppendChild(name);
name.AppendChild
(document.CreateTextNode(reader.GetString(1)));
XmlElement address = document.CreateElement("address");
customer.AppendChild(address);
address.AppendChild
(document.CreateTextNode(reader.GetString(2)));
XmlElement balance = document.CreateElement("balance");
customer.AppendChild(balance);
Decimal b = reader.GetDecimal(3);
balance.AppendChild
(document.CreateTextNode(b.ToString()));
}
document.Save(Console.Out);
reader.Close();
}
示例2: btnLisaa_Click
protected void btnLisaa_Click(object sender, EventArgs e)
{
//create new instance of XmlDocument
XmlDocument theNews = new XmlDocument();
//load from file
theNews.Load(Server.MapPath("~/XML/News.xml"));
//create nodes
XmlElement theNewsTag = theNews.CreateElement("news");
XmlElement theTitleTag = theNews.CreateElement("title");
XmlElement theContentsTag = theNews.CreateElement("contents");
XmlElement theDateTag = theNews.CreateElement("date");
//create what data nodes have
XmlText theTitleText = theNews.CreateTextNode(txtTitle.Text);
XmlText theContentsText = theNews.CreateTextNode(txtContents.Text);
XmlText theDateText = theNews.CreateTextNode(System.DateTime.Now.ToString("r"));
//append them
theTitleTag.AppendChild(theTitleText);
theContentsTag.AppendChild(theContentsText);
theDateTag.AppendChild(theDateText);
theNewsTag.AppendChild(theTitleTag);
theNewsTag.AppendChild(theContentsTag);
theNewsTag.AppendChild(theDateTag);
//put all under the News tag
theNews.DocumentElement.PrependChild(theNewsTag);
// save the file
theNews.Save(Server.MapPath("~/XML/News.xml"));
}
示例3: ErrorResponse
private void ErrorResponse(int errNum, string errText)
{
try
{
XmlDocument d = new XmlDocument();
XmlElement root = d.CreateElement("response");
d.AppendChild(root);
XmlElement er = d.CreateElement("error");
root.AppendChild(er);
er.AppendChild(d.CreateTextNode(errNum.ToString()));
if (errText != "")
{
System.Xml.XmlElement msg = d.CreateElement("message");
root.AppendChild(msg);
msg.AppendChild(d.CreateTextNode(errText));
}
d.Save(Response.Output);
Response.End();
}
catch (Exception)
{
//handle the error.
}
}
示例4: AddXML
//将发帖内容保存到XML文件中的方法
public void AddXML(string filename, string title, string content, string user)
{
XmlDocument mydoc = new XmlDocument();
mydoc.Load(filename);
//添加帖子主题
XmlElement ele = mydoc.CreateElement("title");
XmlText text = mydoc.CreateTextNode(title);
//添加发帖时间
XmlElement ele1 = mydoc.CreateElement("posttime");
XmlText text1 = mydoc.CreateTextNode(DateTime.Now.ToString());
//添加发帖内容
XmlElement ele2 = mydoc.CreateElement("content");
XmlText text2 = mydoc.CreateTextNode(content);
//添加发帖人
XmlElement ele3 = mydoc.CreateElement("postuser");
XmlText text3 = mydoc.CreateTextNode(user);
//添加文件的节点-msgrecord
XmlNode newElem = mydoc.CreateNode("element", "xmlrecord", "");
//在节点中添加元素
newElem.AppendChild(ele);
newElem.LastChild.AppendChild(text);
newElem.AppendChild(ele1);
newElem.LastChild.AppendChild(text1);
newElem.AppendChild(ele2);
newElem.LastChild.AppendChild(text2);
newElem.AppendChild(ele3);
newElem.LastChild.AppendChild(text3);
//将结点添加到文档中
XmlElement root = mydoc.DocumentElement;
root.AppendChild(newElem);
//获取文件路径
int index = filename.LastIndexOf(@"\");
string path = filename.Substring(0, index);
//新文件名
path = path + @"\" + xmlfilename + "file.xml";
FileStream mystream = File.Create(path);
mystream.Close();
//保存所有修改-到指定文件中:注意编码语言的选择
XmlTextWriter mytw = new XmlTextWriter(path, Encoding.Default);
mydoc.Save(mytw);
mytw.Close();
}
示例5: DocumentFragment
public static void DocumentFragment()
{
var xmlDocument = new XmlDocument();
var fragment = xmlDocument.CreateDocumentFragment();
var text1 = xmlDocument.CreateTextNode("test_test1");
var text2 = xmlDocument.CreateTextNode("test_test2");
fragment.Normalize();
Assert.Equal(String.Empty, fragment.OuterXml);
}
示例6: NameOfAllTypes
public static void NameOfAllTypes()
{
var xmlDocument = new XmlDocument();
var element = xmlDocument.CreateElement("newElem");
Assert.Equal("newElem", element.Name);
var attribute = xmlDocument.CreateAttribute("newAttr");
Assert.Equal("newAttr", attribute.Name);
var text = xmlDocument.CreateTextNode("");
Assert.Equal("#text", text.Name);
var cdata = xmlDocument.CreateCDataSection("");
Assert.Equal("#cdata-section", cdata.Name);
var pi = xmlDocument.CreateProcessingInstruction("PI", "");
Assert.Equal("PI", pi.Name);
var comment = xmlDocument.CreateComment("some text");
Assert.Equal("#comment", comment.Name);
var fragment = xmlDocument.CreateDocumentFragment();
Assert.Equal("#document-fragment", fragment.Name);
}
示例7: CreateXMLElement
public static XmlElement CreateXMLElement(XmlDocument xmlDoc, string name, string value)
{
XmlElement xmlElement = xmlDoc.CreateElement(name);
XmlText xmlText = xmlDoc.CreateTextNode(value);
xmlElement.AppendChild(xmlText);
return xmlElement;
}
示例8: NodeTypeTest
public static void NodeTypeTest()
{
var xmlDocument = new XmlDocument();
var newNode = xmlDocument.CreateTextNode(String.Empty);
Assert.Equal(XmlNodeType.Text, newNode.NodeType);
}
示例9: Create
public override IXMLNode Create(string name, string text)
{
XmlDocument doc = new XmlDocument();
XmlElement element = doc.CreateElement(name);
doc.AppendChild(element);
element.AppendChild(doc.CreateTextNode(text));
return new SystemXMLNode(doc);
}
示例10: ButtonSubmit_Click
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Messages.xml"));
XmlElement Customers = doc.CreateElement("Customers");
XmlElement Customer = doc.CreateElement("Customer");
XmlElement datetime = doc.CreateElement("DateTime");
XmlText datetext = doc.CreateTextNode(DateTime.Now.ToString());
XmlElement nameE = doc.CreateElement("Name");
XmlText nameT = doc.CreateTextNode(TextBoxName.Text);
XmlElement EmailE = doc.CreateElement("Email");
XmlText EmailT = doc.CreateTextNode(TextBoxEmail.Text);
XmlElement CommentE = doc.CreateElement("Comments");
XmlText CommentT = doc.CreateTextNode(TextBoxComments.Text);
datetime.AppendChild(datetext);
nameE.AppendChild(nameT);
EmailE.AppendChild(EmailT);
CommentE.AppendChild(CommentT);
Customer.AppendChild(datetime);
Customer.AppendChild(nameE);
Customer.AppendChild(EmailE);
Customer.AppendChild(CommentE);
doc.DocumentElement.AppendChild(Customer);
doc.Save(Server.MapPath("Messages.xml"));
DoneLabel.Text = "Thank You For Your Comments!!";
}
示例11: TextNode
public static void TextNode()
{
var xmlDocument = new XmlDocument();
var node = xmlDocument.CreateTextNode("textnode");
Assert.Equal("textnode", node.Value);
node.Value = "some new text";
Assert.Equal("some new text", node.Value);
}
示例12: CallAppendChildOnTextNode
public static void CallAppendChildOnTextNode()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<a>text node</a>");
var text = xmlDocument.CreateTextNode("text");
Assert.Throws<InvalidOperationException>(() => xmlDocument.DocumentElement.FirstChild.AppendChild(text));
}
示例13: RSSOpret
public static void RSSOpret(int idvalue)
{
DataClassesDataContext db = new DataClassesDataContext();
List<dbCategory> ListCategory = db.dbCategories.Where(i => i.Id == idvalue).ToList();
foreach (var itemChannel in ListCategory)
{
XmlDocument dom = new XmlDocument();
XmlProcessingInstruction xpi = dom.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
dom.AppendChild(xpi);
XmlElement rss = dom.CreateElement("rss");
rss.SetAttribute("version", "2.0");
XmlElement addRes = dom.CreateElement("channel");
XmlElement navn = dom.CreateElement("title");
navn.AppendChild(dom.CreateTextNode(itemChannel.Title));
addRes.AppendChild(navn);
XmlElement status = dom.CreateElement("description");
status.AppendChild(dom.CreateTextNode(itemChannel.Description));
addRes.AppendChild(status);
XmlElement links = dom.CreateElement("link");
links.AppendChild(dom.CreateTextNode(Url + "Categories.aspx?category_id='" + itemChannel.Id));
addRes.AppendChild(links);
List<dbNew> ListNews = db.dbNews.Where(i => i.CategoryId == idvalue).OrderByDescending(d => d.PostDate).ToList();
foreach (var item in ListNews)
{
XmlElement addNew = dom.CreateElement("item");
XmlElement titlenews = dom.CreateElement("title");
titlenews.AppendChild(dom.CreateTextNode(item.Title));
addNew.AppendChild(titlenews);
XmlElement statusNew = dom.CreateElement("description");
statusNew.AppendChild(dom.CreateTextNode(item.Content));
addNew.AppendChild(statusNew);
XmlElement linkNew = dom.CreateElement("link");
linkNew.AppendChild(dom.CreateTextNode(Url + "News.aspx?category_id=" + itemChannel.Id + "&news_id=" + itemChannel.Id));
addNew.AppendChild(linkNew);
addRes.AppendChild(addNew);
}
rss.AppendChild(addRes);
dom.AppendChild(rss);
dom.Save(HttpContext.Current.Server.MapPath("~/feeds/") + itemChannel.Id + "_" + itemChannel.Title + ".xml");
}
}
示例14: Main
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("..//..//..//..//Cars.xml");
//OutputNode (doc.DocumentElement);
// Удалить первый элемент Cars
XmlNode root = doc.DocumentElement;
root.RemoveChild(root.FirstChild);
// Создать узлы элементов.
XmlNode bike = doc.CreateElement("Motorcycle");
XmlNode elem1 = doc.CreateElement("Nanufactured");
XmlNode elem2 = doc.CreateElement("Model");
XmlNode elem3 = doc.CreateElement("Year");
XmlNode elem4 = doc.CreateElement("Color");
XmlNode elem5 = doc.CreateElement("Engine");
// Создать текстовые узлы
XmlNode text1 = doc.CreateTextNode("Harley-Davidson Motor Co. Inc.");
XmlNode text2 = doc.CreateTextNode("Harley 20J");
XmlNode text3 = doc.CreateTextNode("1920");
XmlNode text4 = doc.CreateTextNode("Olive");
XmlNode text5 = doc.CreateTextNode("37 HP");
// Присоединить текстовые узлы к узлам элементов
elem1.AppendChild(text1);
elem2.AppendChild(text2);
elem3.AppendChild(text3);
elem4.AppendChild(text4);
elem5.AppendChild(text5);
// Присоединить узлы элементов к узлу bike
bike.AppendChild(elem1);
bike.AppendChild(elem2);
bike.AppendChild(elem3);
bike.AppendChild(elem4);
bike.AppendChild(elem5);
// Присоединить узел bike к корневому узлу
root.AppendChild(bike);
// Сохранить измененный документ
doc.Save("Motorcycle.xml");
}
示例15: ElementNodeWithOneChildDeleteItInsertNewChild
public static void ElementNodeWithOneChildDeleteItInsertNewChild()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<top><child /></top>");
xmlDocument.DocumentElement.RemoveChild(xmlDocument.DocumentElement.FirstChild);
var newNode = xmlDocument.CreateTextNode("text node");
xmlDocument.DocumentElement.AppendChild(newNode);
Assert.NotNull(xmlDocument.DocumentElement.FirstChild);
Assert.Same(newNode, xmlDocument.DocumentElement.FirstChild);
}