Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : need help on how to add comment to xml schema with C#


comic_rage NO[at]SPAM yahoo.com
10/30/2005 9:58:08 AM
how do you add a comment line/section to an xml schema xsd file?

like this

<!-- ===============================================================
-->
<!-- =================== My comment line ========================
-->
<!-- ===============================================================
-->

I like to add a section before each element. Currently, I am creating a
large xsd file with many elements.

Thanks
Martin Honnen
10/31/2005 12:00:00 AM


[quoted text, click to view]

If you treat an XSD document as a normal XML document that your create
or manipulate with APIs like XmlTextWriter or the DOM/XmlDocument then
you can create comments as usual, for XmlTextWriter you can use WriteComment
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlTextWriterClassWriteCommentTopic.asp>
for the DOM you can use CreateComment
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassCreateCommentTopic.asp>

If you are using the Schema Object Model (SOM) then as far as I am
currently aware there are no ways in .NET to have top level comments
created, however you should be able to include comments in the
documentation e.g. the following code snippet

XmlSchema xmlSchema = new XmlSchema();
XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();
XmlDocument helperDocument = new XmlDocument();
XmlComment comment = helperDocument.CreateComment(
"Schema comment 1");
documentation.Markup = new XmlNode[1] { comment };
annotation.Items.Add(documentation);
xmlSchema.Items.Add(annotation);

xmlSchema.Compile(new ValidationEventHandler(ValidationHandler));

xmlSchema.Write(Console.Out);

yields the schema

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation>
<!--Schema comment 1-->
</xs:documentation>
</xs:annotation>
</xs:schema>


--

Martin Honnen --- MVP XML
Oleg Tkachenko [MVP]
10/31/2005 11:07:32 AM
[quoted text, click to view]

How do you create it?

--
Oleg Tkachenko [XML MVP, MCAD]
AddThis Social Bookmark Button