469,917 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Using annotations in .xsd file to pass metadata

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
given elements of the schema (tables and columns) that the application also
requires. I've guessed that Annotations are a way to do this, so added
<xs:annotation> elements to the xsd file (see example below).

I can set up the dataset fine:

Dim ds As New DataSet()
ds.ReadXmlSchema("XMLSchema1.xsd")

All tables and columns set up beautifully. But what object do I use to get
at the metadata in the annotations, and associate it easily with the
relevant tables and columns within the dataset? I've played with the
xmlDataDocument class, the xmlSchemaAnnotated class, and various others, but
I'm fast losing contact with the ground...

Alternatively, is there a better way to pass such metadata?

Thanks!

Jonathan

Here's the sample xsd file:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Table1">
<xs:complexType>
<xs:annotation>
<xs:appinfo>Meta data about Table1</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="ID1" type="xs:integer">
<xs:annotation>
<xs:appinfo>Metat data about column ID1</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Text1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:annotation>
<xs:appinfo>Meta data about Table2</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="ID2" type="xs:integer" />
<xs:element name="Text2" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Nov 11 '05 #1
1 2751
Thanks for the suggestion.
XmlSchema class yes - but it's difficult to align this with the dataset's
inferred tables and columns.

I think I've cracked it another way (by checking what happens to the xml
when I create a dataset the way I want it, then use WriteXMLSchema to see
what xml it generates). The ExtendedProperties property of a table or column
emerges in xml like this:

<xs:element name="Table1" msprop:MyTableProperty="MyTablePropertyValue">

It looks like I can use this msprop: namespace to create the metadata I need
and have it transported into ExtendedProperties properties within the tables
and columns, where it's easy to get at.

Jonathan
"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl...
Have you tried using the XmlSchema class?

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Gibbs" <jo******************@dial.pipex.com> wrote in message
news:4L******************@news-text.cableinet.net...
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
given elements of the schema (tables and columns) that the application

also
requires. I've guessed that Annotations are a way to do this, so added
<xs:annotation> elements to the xsd file (see example below).

I can set up the dataset fine:

Dim ds As New DataSet()
ds.ReadXmlSchema("XMLSchema1.xsd")

All tables and columns set up beautifully. But what object do I use to get at the metadata in the annotations, and associate it easily with the
relevant tables and columns within the dataset? I've played with the
xmlDataDocument class, the xmlSchemaAnnotated class, and various others,

but
I'm fast losing contact with the ground...

Alternatively, is there a better way to pass such metadata?

Thanks!

Jonathan

Here's the sample xsd file:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Table1">
<xs:complexType>
<xs:annotation>
<xs:appinfo>Meta data about Table1</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="ID1" type="xs:integer">
<xs:annotation>
<xs:appinfo>Metat data about column ID1</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Text1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:annotation>
<xs:appinfo>Meta data about Table2</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="ID2" type="xs:integer" />
<xs:element name="Text2" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Michael Sparks | last post: by
6 posts views Thread by Nathan Kovac | last post: by
2 posts views Thread by EP | last post: by
6 posts views Thread by gregarican | last post: by
44 posts views Thread by John Dann | last post: by
5 posts views Thread by Luis Zarrabeitia | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.