all groups > dotnet xml > october 2005 >
You're in the

dotnet xml

group:

Need help with xml schema to add documentation with elements


Need help with xml schema to add documentation with elements comic_rage NO[at]SPAM yahoo.com
10/28/2005 4:08:57 PM
dotnet xml:
Hi,

I am trying to add an annotation with a documentation, which contains
several nodes. So far, I having a problem on how to code this with C#.

Any help is appreciated.

<xsd:annotation>
<xsd:documentation>
<Description>my description</Description>
<Year>2004</Year>
<Level>Final Release</Level>
<Date>February 11, 2005</Date>
</xsd:documentation>
</xsd:annotation>


public XmlSchemaAnnotation CreateAnnotation(bool bAddDoc, bool
bAddDocElements, string strDocNodeName)
{
XmlSchemaAnnotation annot = new XmlSchemaAnnotation();

if (bAddDoc)
{
XmlSchemaDocumentation doc = new XmlSchemaDocumentation();
// add document node
annot.Items.Add(doc);
// Add elements under the document
if (bAddDocElements)
{
doc.Markup = CreateElementNodes();
}
else
{

doc.Markup = CreateDocumentNode(strDocNodeName);
}
}

return annot;
}


public static XmlElement[] CreateElementNodes()
{
XmlDocument doc = new XmlDocument();

return new XmlElement[1]{doc.CreateElement("prefix", "localname",
"nsURI")};
}
Re: Need help with xml schema to add documentation with elements Martin Honnen
10/29/2005 12:00:00 AM


[quoted text, click to view]

Here is a simple example:

XmlSchema schema = new XmlSchema();
XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();
XmlDocument xmlDocument = new XmlDocument();
XmlElement xhtmlParagraph1 = xmlDocument.CreateElement("p",
"http://www.w3.org/1999/xhtml");
xhtmlParagraph1.AppendChild(xmlDocument.CreateTextNode(
"This is a schema example."));
XmlElement xhtmlParagraph2 = xmlDocument.CreateElement("p",
"http://www.w3.org/1999/xhtml");
xhtmlParagraph2.AppendChild(xmlDocument.CreateTextNode(
"Kibology for all."));
documentation.Markup = new XmlNode[2] {xhtmlParagraph1,
xhtmlParagraph2};
annotation.Items.Add(documentation);
schema.Items.Add(annotation);

schema.Compile(new ValidationEventHandler(ValidationHandler));

XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new
NameTable());
namespaceManager.AddNamespace("xs", XmlSchema.Namespace);
namespaceManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

schema.Write(Console.Out, namespaceManager);

Schema generated is

<xs:schema xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation>
<p xmlns="http://www.w3.org/1999/xhtml">This is a schema example.</p>
<p xmlns="http://www.w3.org/1999/xhtml">Kibology for all.</p>
</xs:documentation>
</xs:annotation>
</xs:schema>

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button