Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to read data from the GUI screen. Which has for example, 1. Name 2. Sub-Name 3. Favorite Numbers.

The "Name", "Sub-Name" and "Favorite Numbers are text boxes.I would create more Names by appending the details to the xml document. is there any class implementation for storing the values from GUI before writing to the XML. In my case by using the class SubName like

C#
Class SubName
{
public SubName
{
Num = new List<int>();
}
public string Sub-Name{get;set;}
public list<int> Num{get;set;}
}
</int></int>


i tried to store the "Num" values in the List. I need to validate all of the Sub-Names to be made ready to write to XML, as there is certain rule that limits the total sum of "Num" values present in all of Sub-Names.

so, by having
<pre lang="c#">SubName[] subs = new SubName[10]


and assign the values that i read from the GUI screen to the class values by,

C#
subs[0] = new SubName();
subs[0].Sub-Name = txtboxSubName.Text
subs[0].Num = listNum


where, listNum is of type
<pre lang="c#">List<int></int>
.

My problem is while creating the XML tags, the Sub-Name is properly written but the Num values are not present. Is there any solution. Or else is there any better method than this. The expected XML tags are presented below...

HTML
<Header>
<names>
<name>TEST</name><sub>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
</sub></names>
<names>
<name>ROTW</name><sub>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
<sub-name>XYZ</sub-name>
<num>1</num><num>2</num><num>3</num><num>4</num><num>5</num><num>6</num><num>7</num>
</sub></names></Header>
Posted
Updated 5-Sep-11 5:59am
v2
Comments
GParkings 5-Sep-11 12:01pm    
You describe your data model and your expected output but i cant see anywhere the code you are using to generate your XML output from your data model. As this is the bit of code that is not behaving as expected you will probably need to include it before anyone is able to help you

1 solution

Are you going to use XML ad-hoc? Why would you need it? Better use Data Contract and System.Runtime.Serialization.DataContractSerializer. It will help you to store and load (restore) any data without manual work with XML. You will get a powerful tool with capabilities of having world-unique schema, persisting arbitrary objects sets of arbitrary structure (not only trees) and means of backup compatibility while migrating the schema — all without your effort.

See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[^].

See also my past solutions where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA
 
Share this answer
 
v3
Comments
Wendelius 5-Sep-11 12:05pm    
Exactly the right way to go, my 5
Sergey Alexandrovich Kryukov 5-Sep-11 12:06pm    
Thank you, Wika.
--SA
Wendelius 5-Sep-11 12:07pm    
Looks like you have given me a new nickname :)
Murali1010 6-Sep-11 9:07am    
Thanks for the reply...Like, i have multi-level tags since each "Name" is associated with many "Sub-Names", Each "sub-Name' is in-turn assoicated with many "Nums". So, how should I write the class, so that it identifies the tag levels properly. the MSDN example just tells about one level.Can you provide me any clue by giving me an example code for the same.

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