GRChandrashekar
asked on
C# XML File to Datatable
Hi, I have an XML file like this.
<?xml version="1.0" encoding="utf-8" ?>
<rootelement>
<titleform>
<formname>title</formname>
<controlname>tbxdescriptio n</control name>
<visible>true</visible>
<requiredfiled>true</requi redfiled>
</titleform>
<Memberform>
<formname>member</formname >
<controlname>tbxmemberid</ controlnam e>
<visible>false</visible>
<requiredfiled>false</requ iredfiled>
</Memberform>
</rootelement>
now in C# I need output as follows. I Should be able to pass the form name through code and desired output should result in datatable. Example: If I pass formname as title, member should not appear in datatable. How do I do this ?
FormName ControlName RequiredField Visible
title tbxtitle true true
Member tbxmemberid false false
<?xml version="1.0" encoding="utf-8" ?>
<rootelement>
<titleform>
<formname>title</formname>
<controlname>tbxdescriptio
<visible>true</visible>
<requiredfiled>true</requi
</titleform>
<Memberform>
<formname>member</formname
<controlname>tbxmemberid</
<visible>false</visible>
<requiredfiled>false</requ
</Memberform>
</rootelement>
now in C# I need output as follows. I Should be able to pass the form name through code and desired output should result in datatable. Example: If I pass formname as title, member should not appear in datatable. How do I do this ?
FormName ControlName RequiredField Visible
title tbxtitle true true
Member tbxmemberid false false
ASKER
This is not answered
Example: If I pass formname as title, member should not appear in datatable. How do I do this ?
Example: If I pass formname as title, member should not appear in datatable. How do I do this ?
i don't understand.
what do u mean u pass formname as titleform?
what do u mean u pass formname as titleform?
ASKER
Refer this.
<titleform>
<formname>title</formname>
<controlname>tbxdescriptio n</control name>
<visible>true</visible>
<requiredfiled>true</requi redfiled>
</titleform>
I should be able to pass title as input. Then output should be
FormName ControlName RequiredField Visible
title tbxtitle true true
<titleform>
<formname>title</formname>
<controlname>tbxdescriptio
<visible>true</visible>
<requiredfiled>true</requi
</titleform>
I should be able to pass title as input. Then output should be
FormName ControlName RequiredField Visible
title tbxtitle true true
so if the value of formname element is "title" then it shouldn't be included in the datatable?
ASKER
If the value for formname element is "title" then "member" should not be included in datatable
If the value for formname element is "member" then "title" should not be included in datatable
If the value for formname element is "member" then "title" should not be included in datatable
sorry u gotta be more clear.
there are 2 elements in your xml: titleform and Memberform.
now please describe the use cases.
which element is not suppose to be insert to the datatable? and when?
there are 2 elements in your xml: titleform and Memberform.
now please describe the use cases.
which element is not suppose to be insert to the datatable? and when?
ASKER
from C# if i pass value as titleform, then output should be
FormName ControlName RequiredField Visible
title tbxtitle true true
from C# if i pass value as memberform, then output should be
FormName ControlName RequiredField Visible
Member tbxmemberid false false
FormName ControlName RequiredField Visible
title tbxtitle true true
from C# if i pass value as memberform, then output should be
FormName ControlName RequiredField Visible
Member tbxmemberid false false
>>from C# if i pass value as titleform
what is that mean?
pass where?
what is that mean?
pass where?
ASKER
should be something like
var root = XElement.Load(@"c:\temp\1. xml\title" );
I mean pass to XML
var root = XElement.Load(@"c:\temp\1.
I mean pass to XML
U cant pass variable to xml like this.
U can have a function which accept either title or member, and the function will populate datatable accordingly.
What i failed to understand is what should the results.
U can have a function which accept either title or member, and the function will populate datatable accordingly.
What i failed to understand is what should the results.
ASKER
Result is here
from C# if i pass value as titleform, then output should be
FormName ControlName RequiredField Visible
title tbxtitle true true
from C# if i pass value as memberform, then output should be
FormName ControlName RequiredField Visible
Member tbxmemberid false false
from C# if i pass value as titleform, then output should be
FormName ControlName RequiredField Visible
title tbxtitle true true
from C# if i pass value as memberform, then output should be
FormName ControlName RequiredField Visible
Member tbxmemberid false false
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
These lines (rows[1]); (rows[0]);in resharper says Co-variant conversion from string to object can cause run time exception on write operation
according to the xml u posted u have 2 inner elements, one for titleform and one for memberform.
Open in new window