473,616 Members | 2,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the annotation of an enumeration

I have the following Schema (XMLSchema1.xsd ):

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="XMLSchema1 "
targetNamespace ="http://tempuri.org/XMLSchema1.xsd"
elementFormDefa ult="qualified"
xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="ht tp://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleTyp e name="FruitType ">
<xs:annotatio n>
<xs:appinfo>H as a color</xs:appinfo>
</xs:annotation>
<xs:restricti on base="xs:string ">
<xs:enumerati on value="Apple">
<xs:annotatio n>
<xs:appinfo>I s green</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumerati on value="Oranges" >
<xs:annotatio n>
<xs:appinfo>I s orange</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>

<xs:element name="Bowl">
<xs:complexType >
<xs:sequence>
<xs:element name="Fruit" type="FruitType " maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

the following Xml (XMLFile1.xml):

<?xml version="1.0" encoding="utf-8" ?>
<Bowl xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocat ion="http://tempuri.org/XMLSchema1.xsd
XMLSchema1.xsd" >
<Fruit>Apple</Fruit>
</Bowl>

And the following code:

XmlSchema schema;
using (Stream s =
(Assembly.GetEx ecutingAssembly ().GetManifestR esourceStream(" WindowsApplicat ion10.XMLSchema 1.xsd")))
{
schema = XmlSchema.Read( s, null);
}

XmlDocument doc;
using (Stream s =
(Assembly.GetEx ecutingAssembly ().GetManifestR esourceStream(" WindowsApplicat ion10.XMLFile1. xml")))
{
doc = new XmlDocument();
doc.Load(s);
doc.Schemas.Add (schema);
doc.Schemas.Com pile();
doc.Validate(nu ll);
}

if (doc != null && schema != null) {
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(doc.NameTa ble);
nsmgr.AddNamesp ace("rpt", "http://tempuri.org/XMLSchema1.xsd" );

XmlNodeList viewNodes = doc.SelectNodes ("rpt:Bowl/rpt:Fruit",
nsmgr);
foreach (XmlElement viewElem in viewNodes) {
string id = viewElem.InnerT ext;
System.Xml.Sche ma.IXmlSchemaIn fo si = viewElem.Schema Info;

XmlSchemaAnnota tion ann = si.SchemaType.A nnotation;
if (ann != null) {
XmlSchemaAppInf o ai = ann.Items[0] as XmlSchemaAppInf o;
Console.WriteLi ne("The type has annotation: " +
ai.Markup[0].Value);
}

XmlSchemaSimple Type st = si.SchemaType as XmlSchemaSimple Type;

ann = st.Content.Anno tation;
if (ann != null) {
XmlSchemaAppInf o ai = ann.Items[0] as XmlSchemaAppInf o;
Console.WriteLi ne("The enum has annotation: " +
ai.Markup[0].Value);
}
}
}

The annotation for FruitType comes back correctly as 'Has a color', but
there seems to be no annotation available for the actual enum value
itself. Is this a bug? Is there another way to get the annotation of an
enumeration (value)?

Nov 12 '05 #1
1 2282
Never mind. I found the answer:

foreach (XmlElement viewElem in viewNodes) {
string id = viewElem.InnerT ext;
System.Xml.Sche ma.IXmlSchemaIn fo si = viewElem.Schema Info;

XmlSchemaAnnota tion ann = si.SchemaType.A nnotation;
if (ann != null) {
XmlSchemaAppInf o ai = ann.Items[0] as XmlSchemaAppInf o;
Console.WriteLi ne("The type has annotation: " +
ai.Markup[0].Value);
}

XmlSchemaSimple Type st = si.SchemaType as XmlSchemaSimple Type;
XmlSchemaSimple TypeRestriction str = st.Content as
XmlSchemaSimple TypeRestriction ;

foreach (XmlSchemaEnume rationFacet facet in str.Facets) {
ann = facet.Annotatio n;
if (ann != null) {
XmlSchemaAppInf o ai = ann.Items[0] as XmlSchemaAppInf o;
Console.WriteLi ne("The enum has annotation: " +
ai.Markup[0].Value);
}
}
}

Nov 12 '05 #2

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

Similar topics

8
1594
by: Steven Bethard | last post by:
I have a list of strings that looks something like: lst = The parentheses in the labels indicate where an "annotation" starts and ends. So for example, the label '(*)' at index 2 of the list means that I have an annotation at (2, 2), and the labels '(*', '*', '(*', '*))' at indices 4 through 7 mean that I have an annotation at (4, 7) and an annotation at (6, 7).
1
12628
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="red"/> <xsd:enumeration value="yellow"/> <xsd:enumeration value="blue"/> </xsd:simpleType>
34
2603
by: Xah Lee | last post by:
i have a very simple html doc using the following style: <style type="text/css"> ..x-note {background-color:#afeeee; margin:1ex; padding:1ex; float:right; line-height:130%; width:60ex; clear:both;} p {line-height:130%; width:70ex;} </style> typically, the <p> is main text of novels, and in between is <div class=x-note>...</div> that are annotations floating on the right side.
2
2296
by: SA | last post by:
Hi all, in the following situation: <xs:element name="Type"> <xs:simpleType> <xs:restriction base="xs:NMTOKEN">
4
5655
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation" for a second if you don't mind). However, it existed within intuitive language semantics, whereas the new "yield" keyword, while highly convenient, is also one of the most gross warping of language concepts to date... public IEnumerator...
2
1600
by: Andreas Prilop | last post by:
Is Ruby annotation http://www.w3.org/TR/ruby/ suitable for text with musical score written with symbols from http://www.unicode.org/charts/PDF/U1D100.pdf ? -- All free men, wherever they may live, are citizens of Denmark. And therefore, as a free man, I take pride in the words "Jeg er dansker!"
3
2147
by: The Man From SQL | last post by:
Hi there, Here's the problem: our team is working on a web service which formerly took in two user defined types consisting of mostly simple datatypes. Recently we decided to move toward an XML schema to define the two types and the required values to submit rather than having to send .NET-specific types. So one of our team members generated an XSD with substantial annotation explaining to consumers of the web service what each element...
1
2160
by: stran | last post by:
I'm trying to create a simple type that holds two different types. The first is IDREF and the second is an enumeration of string. When I generate a sample xml, I can enter any ID previously stated in the xml and validates correctly. When I try to use one of the enumeration in the drop down list, the xml will not validate. When I validate the xml in xmlspy, i get the error message "IDREF 'endofprogam': referenced ID 'endofprogam' was not found."...
4
3037
by: =?Utf-8?B?cHJhZHk=?= | last post by:
Hello, I am trying to develop an application to view pdf files in ASP.net. I would need to add an annotation to the pdf files. I am trying to capture the place where the click on pdf is happening so that i can store the x,y coordinates and place the particular annotation on those coordinates. I am looking for a pdf viewer through which i can capture the coordinates. Is there any other way for us to create an annote for a pdf? just...
0
8203
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8146
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8592
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8449
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7121
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6097
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4063
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2579
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.