我正在尝试创建一个关于XSD的XML。我生成一个样例XML文件,在该文件中,它以<test tip="abc">2560602000</test>的形式编写了一个元素。
我试图通过C#中的代码生成这一行,我的代码是
writer.WriteStartElement("test", null, "2560602000");
writer.WriteAttributeString("tip", "abc");
writer.WriteEndElement();上面的代码正在生成<test: tip="abc" xmlns:test="2560602000" />
如果我将代码更改为writer.WriteAttributeString("tip", "abc"); writer.WriteElementString("test", null, "");
这是在犯错误。
我的问题是,正如我前面所解释的那样,我如何生成一行?
解决了
我用这个方法解决了我的问题
xw.WriteStartElement("entry");
xw.WriteAttributeString("key", "RecordTotal");
xw.WriteString("10");
xw.WriteEndElement();发布于 2017-05-26 15:15:56
易于使用Xml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XElement test = new XElement("test", new object[] {
new XAttribute("tip", "abc"),
2560602000
});
}
}
}https://stackoverflow.com/questions/44204810
复制相似问题