CSharp - 使用XmlWriter添加属性

  显示原文与译文双语对照的内容
0 0

我试图将下面的属性添加到一个使用iasyncresult的节点上,但是任何人都没有任何想法。

 
<news:news>

 

我正在尝试实现以下功能:


 <url>
 <loc>http://www.example.org/business/article55.html</loc>
 <news:news>
 <news:publication>
 <news:name>The Example Times</news:name>
 <news:language>en</news:language>
 </news:publication>
 <news:access>Subscription</news:access>
 <news:genres>PressRelease, Blog</news:genres>
 <news:publication_date>2008-12-23</news:publication_date>
 <news:title>Companies A, B in Merger Talks</news:title>
 <news:keywords>business, merger, acquisition, A, B</news:keywords>
 <news:stock_tickers>NASDAQ:A, NASDAQ:B</news:stock_tickers>
 </news:news>
 </url>

谢谢

时间: 原作者:

0 0

查看下面关于如何使用XmlWriter处理命名空间的链接

XmlWriter中的命名空间句柄

通过使用WriteAttributeString方法手动写出名称空间声明,然后使用 WriteStartElement ( 字符串,字符串) 重载将将来的元素与该命名空间关联起来,比如


writer.WriteStartElement("root");
writer.WriteAttributeString("xmlns","x", null,"urn:1");
writer.WriteStartElement("item","urn:1");
writer.WriteEndElement();
writer.WriteStartElement("item","urn:1");
writer.WriteEndElement();
writer.WriteEndElement();

原作者:
0 0

 using System;
 using System.Xml;

 class Program
 {
 static void Main(string[] args)
 {
 XmlWriter writer = new XmlTextWriter(Console.Out);
 writer.WriteStartElement("root");
 writer.WriteAttributeString("news","http://www.stackoverflow.com");
 writer.WriteStartElement("news:news");
 writer.WriteStartElement("news:publication");
 writer.WriteElementString("news:name","The Example Times");
 writer.WriteElementString("news:language","en");
//etc
 writer.WriteEndElement();
 writer.WriteEndElement();
 writer.WriteEndElement();
 Console.ReadKey(true);
 }
 }

原作者:
...