My program is currently grabbing all attribute values when I only want a specific one depending on which list box item is checked. Any help would be greatly appreciated, thanks in advance!
XML:
<Products>
<Equity>
<servers>
<serverEQ>server1</serverEQ>
<serverEQ>server2</serverEQ>
<serverEQ>server3</serverEQ>
</servers>
<sitesE>
<sitesEQ sitePathEQ="\Logs\W3SVC1"><nameEQ>SystemAdmin Site</nameEQ></sitesEQ>
<sitesEQ sitePathEQ="\Logs\W3SVC3"><nameEQ>Direct Access Site</nameEQ></sitesEQ>
<sitesEQ sitePathEQ="\Logs\W3SVC4"><nameEQ>Redirect Site</nameEQ></sitesEQ>
<sitesEQ sitePathEQ="\Logs\W3SVC5"><nameEQ>Download Site</nameEQ></sitesEQ>
</sitesE>
</Equity>
.
.
.
</Products>
C#:
myXML.siteName = "sitesEQ";
myXML.sitePath = "sitePathEQ";
.
.
.
private void Submit_btn_Click(object sender, EventArgs e)
{
XmlElement root = MYproducts.DocumentElement;
XmlNodeList sitelist = root.GetElementsByTagName(myXML.siteName);
foreach (object ServerChecked in serverLISTbox.CheckedItems)
{
string MyServerChecked = ServerChecked.ToString();
MessageBox.Show(MyServerChecked);
foreach (object SiteChecked in siteLISTbox.CheckedItems)
{
foreach (XmlNode s in sitelist)
{
myXML.xmlAttributes = s.Attributes[myXML.sitePath].Value;
MessageBox.Show(myXML.xmlAttributes);
}
}
myXML.xmlAttributes is displaying all attributes regardless of what I have checked.
For example: If I have "Redirect Site" checked I only want the attribute "\Logs\W3SVC4" not all of them.
Your code is quite complex for such a simple problem so, let's break it in pieces.
First of all, you need a method which will return the attribute values for the elements you pass as argument
Second of all, you need a method which will return the selected names from the listbox:
Now, put those two together in your event handler:
Hope this helps...