473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Need help with xml schema to add documentation with elements

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")};
}

Nov 12 '05 #1
1 1860


co********@yahoo.com wrote:
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#.


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.CreateText Node(
"This is a schema example."));
XmlElement xhtmlParagraph2 = xmlDocument.CreateElement("p",
"http://www.w3.org/1999/xhtml");
xhtmlParagraph2.AppendChild(xmlDocument.CreateText Node(
"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
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brett Selleck | last post by:
I would like to start collecting Metadata on my XML schemas. I have searched the web for a method of automatically extracting Metadata from an XSD file and have come up empty handed. Basically what...
7
by: Gili Korman | last post by:
Hi all, I need to create an XSD schema that will reperesent the following: <LIST> <ITEM1/> 0-unbounded <ITEM3/> 0-unbounded </LIST> or
0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
0
by: Uma Abhyankar | last post by:
Hello, I had a program in .NET Beta1, where in I was programmatically traversing the Xml Schema using the given code snippet. However today with migration to Beta2, I am facing a compilation...
2
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void...
2
by: SA | last post by:
Hi all, in the following situation: <xs:element name="Type"> <xs:simpleType> <xs:restriction base="xs:NMTOKEN">
2
by: Uma Abhyankar | last post by:
Hello, I had a program in .NET Beta1, where in I was programmatically traversing the Xml Schema using the given code snippet. However today with migration to Beta2, I am facing a compilation...
4
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I...
3
by: WideBoy | last post by:
Hi, I have a software generated schema which creates a few empty elements, e.g. <xsd:sequence/>. I would like to be able to delete these elements from the schema post-generation using XSLT. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.