我正在使用System.Xml.Schema.XmlSchema
该类以编程方式创建一个 xml 模式,但它的大小变得不可读。有没有办法输出注释和换行符?
这是我的代码的一部分:
XmlSchema schema = new XmlSchema();
schema.TargetNamespace = "my-ns";
schema.Namespaces.Add("","my-ns");
// do stuff here
...
// and then add some comments like <!-- here comes the second part -->
schema.Items.Add(COMMENTLINE); // How does this work? A line break will be fine too.
// and do more stuff
...
// then write it to a file
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using(XmlWriter tw = XmlTextWriter.Create(filename, settings)
{
schema.Write(tw);
}
期望的输出:
<xs:element>
<!-- comment my stuff -->
<xs:sequence>
<xs:element/>
</xs:sequence>
</xs:element>