Question : How to read field names from an XSD file.

Hi Experts,

I have the code snippet I am using that I snatched from the MSDN site and it does seem to iterate through the XSD file that I
am trying to get the field names of all the fields that exist in the XSD file.  I am trying to parse that fields so that I can set
a value in a column on a gridview with the field name from the XSD file.  I tried to access finer details in each XMLSchemaObject,
but it remains hidden or otherwise unavailable to me in the example given below.  

Any help would be most welcome!

TIA,
Bob
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
'Code to walk the XSD File
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Xml.Schema
Imports System.Xml
Imports System.Reflection

Public Class cValidXSD

    Public Shared Sub Main(ByVal FilePath As String)

        'Dim xsd As String = "example.xsd"

        Dim schema As XmlSchema

        Dim reader As XmlTextReader = New XmlTextReader(FilePath)



        Try
            'fs = New FileStream(xsd, FileMode.Open)
            'schema = XmlSchema.Read(fs, New ValidationEventHandler(AddressOf ShowCompileError))

            schema = XmlSchema.Read(reader, Nothing)

            Dim schemaSet As New XmlSchemaSet()
            AddHandler schemaSet.ValidationEventHandler, AddressOf ShowCompileError

            schemaSet.Add(schema)
            schemaSet.Compile()

            Dim compiledSchema As XmlSchema = Nothing

            For Each schema1 As XmlSchema In schemaSet.Schemas()
                compiledSchema = schema1
            Next

            schema = compiledSchema

            If schema.IsCompiled Then
                DisplayObjects(schema)
            End If

        Catch e As XmlSchemaException
            Console.WriteLine("LineNumber = {0}", e.LineNumber)
            Console.WriteLine("LinePosition = {0}", e.LinePosition)
            Console.WriteLine("Message = {0}", e.Message)
            Console.WriteLine("Source = {0}", e.Source)

        End Try
    End Sub 'Main


    Private Overloads Shared Sub DisplayObjects(ByVal o As Object)
        DisplayObjects(o, "")
    End Sub 'DisplayObjects

    Private Overloads Shared Sub DisplayObjects(ByVal o As Object, ByVal indent As String)
        Console.WriteLine("{0}{1}", indent, o)

        Dim property1 As PropertyInfo
        For Each property1 In o.GetType().GetProperties()
            If property1.PropertyType.FullName = "System.Xml.Schema.XmlSchemaObjectCollection" Then

                Dim childObjectCollection As XmlSchemaObjectCollection = CType(property1.GetValue(o, Nothing), XmlSchemaObjectCollection)

                Dim schemaObject As XmlSchemaObject
                For Each schemaObject In childObjectCollection
                    DisplayObjects(schemaObject, indent + ControlChars.Tab)
                    'debug.writeline(schemaobject.xmlschemaappinfo.
                Next schemaObject
            End If
        Next property1
    End Sub 'DisplayObjects

    Private Shared Sub ShowCompileError(ByVal sender As Object, ByVal e As ValidationEventArgs)
        Console.WriteLine("Validation Error: {0}", e.Message)
    End Sub 'ShowCompileError
End Class 'ValidXSD



'XSD File I am trying to read



  
    
      
        
        
        
      
    
  
  
    
      
        
          
            
              
              
              
              
              
              
              
              
              
              
              
              
            
          
        
      
    
  

Answer : How to read field names from an XSD file.

Yea goDaddy kind blows.  I'm not sure about the problem you've had but I host my stuff at HD Web Studios.  They have a gui for editing your php ini right in your control panel and every bell/whistle you could think of.  Customer service is pretty damn good too, they're willing to help out more than I even expected them to.  http://www.hdwebstudios.com/hosting.php.  Good luck, you can keep your points.

Oh, one more thing, I don't know what type of development you are doing (web or app) but there are some things you might want down the road in that list and the last line has the ones that may be affecting your ability to work with files: fopen, fwrite, fread, etc.
Random Solutions  
 
programming4us programming4us