473,434 Members | 1,834 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,434 software developers and data experts.

XSD annotations?

I'm trying to read in a XSD schema with two annotation nodes defined.
The schema seems to load fine but I cannot find the annotations. The
schema is being loaded into a xmlschema object.

When I look at the schema object (element, attribute or etc.) the
annotation of every node is "nothing".

Example schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
<xs:element name="title" type="xs:string">
<xs:annotation>
<xs:documentation>Element Test</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<!-- definition of attributes -->
<xs:attribute name="orderid" type="xs:string">
<xs:annotation>
<xs:documentation>Attribute Test</xs:documentation>
</xs:annotation>
</xs:attribute>
<!-- definition of complex elements -->
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="note" minOccurs="0"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SaleItems">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="orderid" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

Nov 12 '05 #1
7 1606
Anyone? Really need to figure this out.

Nov 12 '05 #2
The following sample code will print the content of the annotation elements:
Text in documentation: Element Test
Text in documentation: Attribute Test

Thanks,
Priya

using System;
using System.Threading;
using System.Xml;
using System.Xml.Schema;

class Annotation{

public static void Main() {
XmlSchema schema = XmlSchema.Read(new XmlTextReader("annot.xsd"), null);
schema.Compile(null);

foreach(XmlSchemaObject schemaObject in schema.Items) {
PrintAnnotation(schemaObject);
}

}

private static void PrintAnnotation(XmlSchemaObject schemaObject) {
XmlSchemaAnnotation annotation;
if (schemaObject is XmlSchemaAnnotated) {
XmlSchemaAnnotated annotated = schemaObject as
XmlSchemaAnnotated;
annotation = annotated.Annotation;
if (annotation != null) {
ProcessAnnotation(annotation);
}
}
}

private static void ProcessAnnotation(XmlSchemaAnnotation
annotation) {
foreach (XmlSchemaObject obj in annotation.Items) {
XmlSchemaDocumentation doc = obj as XmlSchemaDocumentation;
if (doc != null) {
foreach(XmlNode node in doc.Markup) {
switch(node.NodeType) {
case XmlNodeType.Text:
Console.WriteLine("Text in documentation: " +
node.Value);
break;

case XmlNodeType.Element:
Console.WriteLine("Text in documentation: " +
node.InnerText);
break;
}
}
}
}
}
}

"SideByEach" <kn*****@nb.sympatico.ca> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to read in a XSD schema with two annotation nodes defined.
The schema seems to load fine but I cannot find the annotations. The
schema is being loaded into a xmlschema object.

When I look at the schema object (element, attribute or etc.) the
annotation of every node is "nothing".

Example schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
<xs:element name="title" type="xs:string">
<xs:annotation>
<xs:documentation>Element Test</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<!-- definition of attributes -->
<xs:attribute name="orderid" type="xs:string">
<xs:annotation>
<xs:documentation>Attribute Test</xs:documentation>
</xs:annotation>
</xs:attribute>
<!-- definition of complex elements -->
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="note" minOccurs="0"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SaleItems">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="orderid" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

Nov 12 '05 #3
Thanks for the sample. I have two follow up questions for you.

1). How do I tell what element/attribute/etc the annotation belongs to?

2). What's the point of elements/attributes/etc objects "annotation"
attribute if it doesn't seem to hold the annotation for that item?

Nov 12 '05 #4
Here's an example of why I'm getting frustrated:

If TypeOf sObject Is XmlSchemaAnnotated Then
Dim sAnnotated As XmlSchemaAnnotated = DirectCast(sObject,
XmlSchemaAnnotated)
Dim tempAnno As XmlSchemaAnnotation = sAnnotated.Annotation

If Not tempAnno Is Nothing Then
Dim tempMsg As String = GetMessageFromAnno(tempAnno)
End If 'Not tempAnno Is Nothing
End If 'TypeOf sObject Is

The "TypeOf" check passes but "Annotation" property is always nothing.
But if I create a test function that simply loops through all the
objects in the schema looking annotations, it works. What gives?

Nov 12 '05 #5
A little help?

Nov 12 '05 #6
Are you looking for information regarding xsd:annotations in general, or do
you have a specific need you want to use them for?
"SideByEach" <kn*****@nb.sympatico.ca> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
A little help?

Nov 12 '05 #7
I've figured out a little bit about how to reference annotiation in the
XmlSchema object.
The annotation property can exists in one of four different place in
single XmlElement object. For example if an element is a base type,
then the "annotation" property should contain the annotation. The
element's annotation can exist in the "ElementSchemaType.Annotation"
and "SchemaType.Annotation" properties. There is a forth location but I
have been unable to locate it.
I wish there was a simpler way to get the current
element/attribute/etc. annotation.

Nov 12 '05 #8

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

Similar topics

1
by: Efy. | last post by:
Hello, The following problam description I did not need to write, I just copied from the groups from others which met the error and allways the thread was 1 artical the problem was never...
2
by: Charles L | last post by:
I am trying to find a link to the 'C++ Annotations' by Frank Brokken (I think Version 5.2.4 is the latest) that works because I've been unable to find one that does. Can anyone suggest anything? ...
0
by: Charles L | last post by:
Does anyone know if there is any Errata for 'C++ Annotations' by Brokken? Charles Leng
1
by: Moon | last post by:
Well, this is my first attempt at DHTML so I'm asking for some pointers, hopefully in the right groups, follow-up is set. I'm currently working on another translation of an english text and I'd...
1
by: Jonathan Gibbs | last post by:
I'm very new to xml, and struggling a bit.. I want to use an .xsd file passed to a windows application to define a dataset's schema, and also (if possible) pass other metadata associated with...
2
by: Rein Petersen | last post by:
I was wondering if anyone else had experienced a similar issue where it is possible to write xs:annotation elements to a schema (verified in the resulting document streamed to the filesystem) but I...
6
by: Pavel A. | last post by:
How the code annotations ( __in_opt, __out, __checkReturn ... ) are supposed to work ? Are they part of the new MS C language (that's, real tokens understood by the compiler), or always #define'd...
4
by: Tony Lownds | last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
3
by: Sektor van Skijlen | last post by:
Is there any official proposal for annotations in C++0x? So far annotations have been "implicitly" used in many proposals as some (usually) free-form text enclosed in ] (for example, n2493,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.