Solved

Reading annotations in an XSD

Posted on 2006-11-22
8
264 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

13 Experts available now in Live!

Get 1:1 Help Now