Help with simple XPath query?

  • Thread starter sherifffruitfly
  • Start date
S

sherifffruitfly

Hi all,

I'm never gonna get the xml part of c#.... sigh....

My xml file is structured as so:

<?xml version=.....?>
<TheAs>
<TheA filename="name1" enabled="true" />
<TheA filename="name2" enabled="false" />
..
..
..
</TheAs>

I'm trying to update the boolean field - here's what I've pasted
together (doesn't work of course):

string enabledQ = (e.NewValue == CheckState.Checked)?"true":"false";

XmlDocument doc = new XmlDocument();
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(selectedAsPath + selectedAs);
doc.Load(reader);
XmlElement root = doc.DocumentElement;

string nodeNeeded = lv_myListView.Items[e.Index].Text;

string xPathQuery = "/WmpmHistoryFiles/WmpmHistoryFile[filename=
\"" + nodeNeeded + "\"]";

XmlElement tempNode = root.SelectSingleNode(xPathQuery) as
XmlElement;
if (tempNode != null)
{
tempNode.SetAttribute("enabled", enabledQ);
Utility.Utility.OutputToLog("Successfully wrote enabled
value.");
}
else
{
Utility.Utility.OutputToLog("Could not find entry.");
}
catch(Exception ex)
{
Utility.Utility.OutputToLog("Error saving settings to XML file.
\n" + ex.Message);
}
finally
{
doc.Save(selectedAsPath + selectedAs);
if (reader != null)
{
reader.Close();
}
}


Thanks for any help getting the xpath right,

cdj
 
S

sherifffruitfly

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top