簡體   English   中英

以編程方式向 XmlSchema 添加注釋和換行符

[英]Programmatically add comments and linebreaks to XmlSchema

我正在使用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>

它是一個 XML 文檔。 只需使用漂亮的打印機。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM