Solved

Reading annotations in an XSD

Posted on 2006-11-22
8
271 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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