473,394 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help with simple XPath query?

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

Mar 1 '07 #1
2 2788
sherifffruitfly <sh*************@gmail.comwrote:
I'm never gonna get the xml part of c#.... sigh....
Well, XPath is *completely* independent of C#, but there we go...

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 1 '07 #2
On Mar 1, 12:35 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
sherifffruitfly <sherifffruit...@gmail.comwrote:
Could you post a short but complete program which demonstrates the
problem?

Seehttp://www.pobox.com/~skeet/csharp/complete.htmlfor details of
what I mean by that.
Hey! This isn't the LaTeX group! (lol!)

In any case, no worries - got it on my own "@filename" instead of
"filename" in my posted code. I hate xml.

Also needed to close the reader BEFORE saving the documnent...
Thanks anyway,

cdj


Mar 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: R | last post by:
Hello everybody. I'm new to XML and I've got problem with one XPath query. This is my situation: <group> <test required='1'></test> <test required='1' noregexp='1'></test> </group> inside...
1
by: Samik Raychaudhuri | last post by:
Hello, I am having the following XML file: ----- <bibRecords xmlns="http://tempuri.org/bibrecords.xsd"> <bibRecord> <entryID>1</entryID> <tag>Shioura97</tag> <entrytype>Conference...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
0
by: raheel | last post by:
Hi, I have an xml file like this: <posts> <post> <date> <body> ...... I want to select using an XPath expression all posts (post elements) which have the date starting with say '10' (for
2
by: Claudio | last post by:
Hi I'm trying to use XPath queries with streaming XML, but I cannot make it working. The solution I'm trying to implement is: create a XmlNode as soon as I have a full XML element and use the...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to construct an XPath query against an XML document, for a requirement that I have. Below is the XML fragment: <SUBMISSIONS> <SUBMISSION YEAR="2004"> <MONTH...
5
by: tschulken | last post by:
I have a query where i need to look for a value of a lower level xml element based on the value of a parent element existing first. Here is a simple example of the xml <S3Client> <Buttons>...
2
by: hary | last post by:
Hello, I have a C# application that is consuming a C# WebService. I am calling a method on the WebService and it is sending me back a response which contains an XmlDocument: string soapMessage...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.