472,125 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

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

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

Nov 12 '05 #1
2 17452
co********@yahoo.com wrote:
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.


How do you create it?

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Nov 12 '05 #2


co********@yahoo.com wrote:
how do you add a comment line/section to an xml schema xsd file?


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.a sp>

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
http://JavaScript.FAQTs.com/
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Tad Marko | last post: by
reply views Thread by comic_rage | last post: by
13 posts views Thread by Ray Cassick \(Home\) | last post: by
4 posts views Thread by Hemant Shah | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.