473,441 Members | 1,972 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,441 software developers and data experts.

Selecting an Attribute within the SelectNode function.

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 = ??
Nov 16 '05 #1
1 9273
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
Nov 16 '05 #2

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

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
4
by: Martin Lucas-Smith | last post by:
I am wanting to know whether are XHTML1-valid characters for use within an id attribute and/or a name attribute. ...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
1
by: jdhcards | last post by:
Hello, I've been banging my head against a problem all day without a solution, and I'm hoping you all can help. I've got a piece of XML that defines a set of elements in a flat list. Each of...
4
by: visu | last post by:
I need a solution to my problem. the problem is I ll have a button in page ... and when i click it .. content of a div tag has to be get selected (i.e what we normally do with mouse to...
11
by: J_Zanetti | last post by:
Hello everybody, In my applications I've a ton of scripts that use remote XML file to fill forms and evaluate contents; In these scripts I always use the method SelectNode (that, with some...
2
by: dav61000 | last post by:
I am new to VB.net so I am not sure if there is a good way to do this or not but here is my problem. I have created a form with a TreeView control on it. When the user selects a node from the...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.