Solved

Reading annotations in an XSD

Posted on 2006-11-22
8
267 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now