Solved

Reading annotations in an XSD

Posted on 2006-11-22
8
273 Views
Last Modified: 2010-04-23
Hi Guys,

Im struggling to read the values of the annotations in an XSD, I can access the annotation as an object but Im obviously missing something as it cant be as complex to read it and display the xs:documentation element.
Im creating an input form from the xsd and want to use the xs:documentation element value as a tooltip.

Ive been searching for a couple of days now and am ready to pull out my hair, so please help by pointing out the obvious method of doing this.

cheers
Ben
0
Comment
Question by:BBaron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17997319
Ben,

May I be so bold as to ask why you need to do this?

Bob
0
 

Author Comment

by:BBaron
ID: 18002337
Hi Bob,

Im creating an input form from the XSD which is supplied by an outside source, with questions that are also determined by them, I figured it would be easiest to use the xs:documentation element in the annotations to use as a tool tip to expand the question description (as this is already created and produced).

I assume from the question that its not as easy as it seems then? if not why as its possible to write them out but then have no access to whats in them?

Im new to .net so you'll have to excuse any obvious stupidity....

cheers and thanks for the interest
Ben
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18019693
I don't understand.

If you are trying to read <xs:annotation> elements in an XSD, I don't see the <xs:documentation> element.

Can you show me the portion of the XSD that shows what you are trying to read?

Bob

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BBaron
ID: 18019740
Hi Bob,

here we go, Ive obviously jsut taken 1 simple element out of the XSD, youll notice that the xs:documentation  is in the annotation so presumably thats why Im struggling?

<xs:element name="StartDate" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation>The date the entry is to take effect.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:date"/>
</xs:simpleType>
</xs:element>

cheers
Ben
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18019933
How was the XSD file generated?

Bob
0
 

Author Comment

by:BBaron
ID: 18019997
No idea, all I know, and am given is the XSD in that format, in fact multiple XSD files, we have no contact or have any control over the format or the content. The files are also used by other companies whom integrate with the provider.

I assume from that question that a normally well formatted XSD wont have that structure?

cheers
Ben
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 155 total points
ID: 18039739
Nope, annotations are not a normal everyday element to XSD files.  I had to do some homework.

Here is an 2005 (2.0) example of what you should need:

Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Text
Imports System.Xml
Imports System.Xml.Schema

Public Class XsdReader

    Public Function ReadSchema(ByVal fileName As String) As Dictionary(Of String, String)

        Dim dictionary As New Dictionary(Of String, String)

        Dim schema As XmlSchema = XmlSchema.Read(New XmlTextReader(fileName), AddressOf OnValidation)

        Dim name As String = ""
        Dim description As String = ""

        For Each type As XmlSchemaType In schema.Items

            name = type.Name
            description = ""

            If type.Annotation.Items.Count > 0 Then

                If TypeOf type.Annotation.Items(0) Is XmlSchemaDocumentation Then

                    Dim doc As XmlSchemaDocumentation = CType(type.Annotation.Items(0), XmlSchemaDocumentation)

                    Dim sb As New StringBuilder()

                    For Each text As XmlText In doc.Markup
                        sb.Append(text.Value.Replace(vbCrLf, ""))
                    Next text

                    description = sb.ToString().Trim()

                End If
            End If

            dictionary.Add(name, description)

        Next type

        Return dictionary

    End Function

    Private Sub OnValidation(ByVal sender As Object, ByVal e As ValidationEventArgs)

    End Sub

End Class

Bob
0
 

Author Comment

by:BBaron
ID: 18044440
Bob, thats great, absolutly spot on, Ive amended it a little to jsut check for the specific annotation of my current element but your code did the job. Glad I can be of help with you still needing to do some homework :)

many many thanks

Ben
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question