C#使用XmlWriter写" d3p1:string"元件

时间:2015-12-22 10:19:27

标签: c# xml xmlwriter

<Messages xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
      <d3p1:string>sample string 1</d3p1:string>
      <d3p1:string>sample string 2</d3p1:string>
    </Messages>

XmlWriter我想写这个XML

代码:

writer.WriteStartElement("Messages");
writer.WriteAttributeString("xmlns", "d3p1", null, "http://schemas.microsoft.com/2003/10/Serialization/Arrays");

writer.WriteElementString("d3p1:string", "my message");

writer.WriteEndElement();

问题在于

  writer.WriteElementString("d3p1:string", "my message");

无效。

  

&#39;:&#39;字符,十六进制值0x3A,不能包含在a中   名。

如何编写d3p1:string xml标签?

2 个答案:

答案 0 :(得分:4)

还在WriteElementString:

使用名称空间和前缀
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.<YOUR_XML_FILE_NAME>);

答案 1 :(得分:0)

我遇到了类似的问题。我需要写:

<t xml:space="preserve">

这样做的代码是:

writer.WriteAttributeString("xml", "space", "http://www.w3.org/XML/1998/namespace", "preserve")