Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want read a xml file which is as following

XML
<?xml version="1.0" encoding="UTF-8"?>
<category>
<aaa>
<bbb>
<ccc>
<ddd>
<eee>
<abc>name</abc>
<cde>student</cde>
<fff>
<fgh>phone</fgh>
<hij>address</hij>
</fff>
</eee>


so i have xml file so i want to read the xml file and make the changes in the same xml file so i want to display only the selected node which user select like eee so we have display the selected items in lalble and text boxs so when save button is clicked than save the changes to xml file
selected node is eee all the elements in eee node
so we have to display like below

lable         textbox
abc      : name
cde      : student


save button

thanks for the help guys
Posted
Updated 18-Oct-15 0:48am
v3
Comments
George Jonsson 18-Oct-15 6:22am    
You need to format your XML data into a valid format and use the code format to make it easier to read.
Maciej Los 18-Oct-15 6:52am    
What have you tried till now? Where are you stuck?

1 solution

Well... your xml is not well formed. So, based on your example data, i have created simple sample:

C#
string xcontent = @"<?xml version='1.0' encoding='UTF-8'?>
<category>
<aaa>
<bbb>
<ccc>
<ddd>
<eee>
<abc>name</abc>
<cde>student</cde>
<fff>
<fgh>phone</fgh>
<hij>address</hij>
</fff>
</eee>
</ddd>
</ccc>
</bbb>
</aaa>
</category>";

string selectedNode = "eee";

//Replace Parse with Load method
//pass full file name as an argument
XDocument xdoc = XDocument.Parse(xcontent);


var result = xdoc.Descendants(selectedNode)
        .Descendants()
        .Select(x=>new
            {
                nodeName = x.Name.ToString(),
                nodeValue = x.Value.ToString()
            });
foreach(var a in result)
{
	Console.WriteLine("{0} - {1}", a.nodeName, a.nodeValue);
}


Returns:
abc - name
cde - student
fff - phoneaddress
fgh - phone
hij - address
 
Share this answer
 
v2
Comments
manoj1412012 20-Oct-15 1:46am    
Thanks maciej for the help
Maciej Los 20-Oct-15 1:47am    
You're very 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