Hi Cheryl,
"Cheryl" <ch********@aol.com> wrote in message
news:77**************************@posting.google.c om...
I have problems selecting the attribute when I use the SelectNode function.
<book>
<title store='7456' >Nutshell</title>
<author id='1'>Drayton</author>
<xauthor publish = "1" publishtime = "2"/>
<author id='3'>Neward</author>
<author id='2'>Albahari</author>
</book>
doc.Loadxml(dom);
XmlDocument doc = new XmlDocument(dom);
XmlNode docElement = doc.DocumentElement;
XmlNodeList result = SelectNodes("/book/title[@store='7456']")
************************************************** ************
What I am trying to do is assign a variable to each tag attribute
publishtime.
opublishtime = ??
First off, I believe this post belongs in the newsgroup
microsoft.public.dotnet.xml, but
what the heck:
Your XPath looks ok to me, but I'm not really sure what your meaning with
the last
sentence - do you want to assign something to the publishtime attribute on
the subelement
named xauthor? And (it may be a typo) the SelectNodes() call is not called
on an object instance.
Another thing, if the store attribute of title is unique (i.e. the "primary
key"), you could use
the SelectSingleNode() call instead to only select the node you want to
modify.
If so:
XmlElement xauthorElement =
doc.SelectSingleNode("/book/title[@store'7456']/xauthor") as XmlElement;
// this should be an XElement
if (xauthorElement != null)
{
xauthorElement.Attributes["publishtimes"] = 42;
}
....
// store the xml document (if needed).
doc.Save("foobar.xml");
--
Lars Wilhelmsen
http://www.sral.org/
Software Engineer
Teleplan A/S, Norway