Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working in Asp.Net - C#.

I've a coding in VB & is working well
VB
Dim CLEAD As XmlSchemaElement
.
.
.

  reader = New XmlTextReader(xsdFilePath)
            schema = XmlSchema.Read(reader, Nothing)

            For i As Integer = 0 To schema.Items.Count - 1
                If TypeOf schema.Items(i) Is XmlSchemaElement Then
                    CLEAD = schema.Items(i)
                End If
            Next

I tried to convert it into c# as follows
C#
XmlSchemaElement CLEAD;
.
.
.
reader = new XmlTextReader(xsdFilePath);
 schema = XmlSchema.Read(reader, null);

 for (int i = 0; i < schema.Items.Count-1; i++)
            {

                 if (schema.Items[i].GetType() == typeof(XmlSchemaElement))
                     CLEAD = schema.Items[i];
            }


But this line (CLEAD = schema.Items[i];) gives the error: cannot implicitly convert System.Xml.Schema.XmlSchemaObject to System.Xml.Schema.XmlSchemaObjectElement

Please help me to rectify this
Posted
Updated 18-Oct-13 0:17am
v3

1 solution

You may explicitely cast it (you've already checked its type), e.g.
C#
CRMLEAD = (XmlSchemaElement)schema.Items[i];


or you maight use the as operator (see MSDN[^]).
 
Share this answer
 
Comments
sunpop 18-Oct-13 7:20am    
thank u so much
CPallini 18-Oct-13 7:41am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900