Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a xml file with the following format :

XML
<list name="a">
<person>        
    <field name="Name">aaa</field>
    <field name="lname">bb'b'</field>
    <field name="tel">123</field>
    <field name="tel">1234</field>
    <field name="tel">12345</field>
</person>
<person>        
    <field name="Name">vvv</field>
    <field name="lname">fff'</field>
    <field name="tel">1</field>
    <field name="tel">2</field>
    <field name="tel">3</field>
</person>
<person>        
    <field name="Name">ccc</field>
    <field name="lname">bb:'c'</field>
    <field name="tel">4</field>
    <field name="tel">5</field>
    <field name="tel">6</field>
</person>
</list>


and the following struct :
C#
struct person
{
string name;
string lname;
string[] tel;
}

I got confused between different methods to read and write xml with following format I did my best to try methods T but not the result I wanted

I want to :

1- read the file and put the contents to struct array or dataTable to show in gridView.
2- write dataTable or Struct to a file with exacly same format as the input

I did my best to try methods , but not the result I wanted also the xmlWriter doesn't escape the ' and " in values like :
bb'b' instead of bb'b'

What I have tried:

xmlserializer
xmlReader
xmlWriter
generating text manualy
Posted
Updated 30-Jan-17 3:21am

1 solution

0) Use a class instead of a struct.

1) Use serialization to load/save the xml.
 
Share this answer
 

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