pritesh2010 30 Posting Whiz in Training

i have follwing data in datatable how to convert it to xml

ErrorType   UtilityType MstLocCode  MDescription    SubLocCode  SDescription    FieldName   FDescription
    1           Elect       NM0001                  XMN001                      ABC         ddsafs
    1           Elect       NM0001                  XMN001                      XYZ         ddsafs
    1           Elect       NM0001                  XMN001                      LMN         ddsafs
    1           Elect       NM0005                  XMN002      sds     
    1           Elect       NM0006                  XMN002      fghfgh          Gas         ddsafs
    1           Elect       NM0002      asas    
    1           Elect       NM0003      asas    
    1           Alect       NM0004      asas    
    2           Alect       NM0008      asas

and my xml output will be like follwoing

<Country Code=“Test”>
<Error Type=“1”>
    <Utility Name=“Elect”>
        <MSTLOC Code=“NM0001” >
            <SubLocation Code=“XMN001”>
                <Field Name=“ABC” ErrorMessage=“ddsafs”/>
                <Field Name=“XYZ” ErrorMessage=“ddsafs”/>
                <Field Name=“LMN” ErrorMessage=“ddsafs”/>
            </SubLocation>   
        </MSTLOC>
        <MSTLOC Code=“NM0005” >
            <SubLocation Code=“XMN002” ErrorMessage=“sds”/>
            <SubLocation Code=“XMN002”>
                <Field Name=“GAS” ErrorMessage=“ddsafs”/>
            </SubLocation>
        </MSTLOC>
        <MSTLOC Code=“NM0002” ErrorMessage=“asas”>
        <MSTLOC Code=“NM0003” ErrorMessage=“asas”>
    </Utility>
    <Utility Name=“Alect”>
        <MSTLOC Code=“NM0004” ErrorMessage=“asas”>
    </Utility>
</Error>
<Error Type=“2”>
    <Utility Name=“Alect”>
        <MSTLOC Code=“NM0008” ErrorMessage=“asas”>
    </Utility>
</Error>
</Country>

How to do this in one linq query?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.