Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to iterate through an XDocument's Nodes
    primarykey
    data
    text
    <p>I am trying to iterate through my xml document's nodes to get the value for <code>&lt;username&gt;Ed&lt;/username&gt;</code> in each node. I am using Linq to sort the XDocument first, then attempting to loop through the nodes. I can't seem to find the correct foreach loop to achieve this. Any help is appreciated.</p> <pre><code>var doc = XDocument.Load("files\\config.xml"); var newDoc = new XDocument(new XElement("Config", from p in doc.Element("Config").Elements("Profile") orderby int.Parse(p.Element("order").Value) select p)); foreach (XElement xe in newDoc.Nodes()) { MessageBox.Show(xe.Element("username").Value); } // XML document &lt;Config&gt; &lt;Profile&gt; &lt;id&gt;Scope&lt;/id&gt; &lt;username&gt;Scope 1&lt;/username&gt; &lt;password&gt;...&lt;/password&gt; &lt;cdkey&gt;0000&lt;/cdkey&gt; &lt;expkey&gt;&lt;/expkey&gt; &lt;cdkeyowner&gt;Scope&lt;/cdkeyowner&gt; &lt;client&gt;W2BN&lt;/client&gt; &lt;server&gt;[IP]&lt;/server&gt; &lt;homechannel&gt;Lobby&lt;/homechannel&gt; &lt;load&gt;1&lt;/load&gt; &lt;order&gt;2&lt;/order&gt; &lt;/Profile&gt; &lt;Profile&gt; &lt;id&gt;Scope 2&lt;/id&gt; &lt;username&gt;Scope 2&lt;/username&gt; &lt;password&gt;...&lt;/password&gt; &lt;cdkey&gt;0000&lt;/cdkey&gt; &lt;expkey&gt;&lt;/expkey&gt; &lt;cdkeyowner&gt;Scope&lt;/cdkeyowner&gt; &lt;client&gt;W2BN&lt;/client&gt; &lt;server&gt;[IP]&lt;/server&gt; &lt;homechannel&gt;Lobby&lt;/homechannel&gt; &lt;load&gt;1&lt;/load&gt; &lt;order&gt;1&lt;/order&gt; &lt;/Profile&gt; &lt;/Config&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload