c# - Trying to read values from an XML file -


trying read each individual address value in each endpoint element , display each individual 1 in seperate textbox.

<client>     <endpoint address="http://127.0.0.1:" />   <endpoint address="http://127.0.0.1:" />   <endpoint address="net.tcp://127.0.0.1:" /> </client> 

i can read xml data , display value of last element. first try @ developing in c#.

here bit of code have written:

        xmlreader readfile = xmlreader.create(agentconfig.filename);         while (readfile.read())         {             if ((readfile.nodetype == xmlnodetype.element) && (readfile.name == "endpoint"))             {                 if (readfile.hasattributes)                 {                     textbox2.text = readfile.getattribute("address");                     textbox3.text = readfile.getattribute("address");                 }             }         } 

in meantime looking answer on own, input appreciated! :)

using linq xml more convenient case:

 var addresses = xdocument.load(agentconfig.filename)                           .descendants("endpoint")                           .select(x => (string)x.attribute("address"))                           .tolist(); 

the result list<string>, so, can assign textboxes index:

textbox1.text = addresses[0]; textbox2.text = addresses[1]; textbox3.text = addresses[2]; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -