Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading annotations in an XSD

Posted on 2006-11-22
8
Medium Priority
?
278 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 620 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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