473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.DocumentEle ment;
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 9286
Hi Cheryl,

"Cheryl" <ch********@aol .com> wrote in message
news:77******** *************** ***@posting.goo gle.com...
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.DocumentEle ment;
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.publi c.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 SelectSingleNod e() call instead to only select the node you want to
modify.

If so:
XmlElement xauthorElement =
doc.SelectSingl eNode("/book/title[@store'7456']/xauthor") as XmlElement;
// this should be an XElement
if (xauthorElement != null)
{
xauthorElement. Attributes["publishtim es"] = 42;
}
....
// store the xml document (if needed).
doc.Save("fooba r.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
3654
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. And i have things to offer, and to request. And a lot of ideas, but who needs them.... here's an example (from type_struct.py):
1
2975
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 following statement fails to find a node (even though one exists in the XML) if the value of the LDAPServerURL attribute is \\LocalServer but works if the value is "LocalServer".
5
3355
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 columns when some cells are empty. Is there a way to use the ss:Index to account for the missing <Cell elements? Thank you for any suggestions. ====================
4
21283
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. http://validator.w3.org/check?uri=http://www-thaihydro.geog.cam.ac.uk/riverslice/&ss=1&verbose=1 (e.g. see line 77) suggests that it is valid, but the spec suggests that it is not. More detail:
2
3650
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 /////////////////////////////////////////////////////////////////////////////////////// <form action="whatever.php" method="post"> <select name="zip_code" onchange="makeRequest('getCity.php?state='+this.form.zip_code.options.value)" multiple="multiple" size="20">
1
1546
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 these elements has an attribute "Id" which has a unique value. Some of these elements have a parent-child relationship, specified with a "ResultId" attribute in one of the child nodes. <element id=1>
4
3696
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 selecting some part of a page).. then i can do CTRl+C to copy the selected div content.. to paste it in MS Word or in any other external application..
11
6095
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 workaround, works fine also in Mozilla). I've just found out that this method doesnt work in Safari browser, therefore my applications are not usable by this browser. Can anyone provide me any solution or workaround to be able to read XML files in...
2
4065
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 treeview I would like to use the AFTER_SELECT method to bring up a new form if possible containing a dataset for the record selected. OR as an alternative I would like to bring up a dataset for that record selected on the same form. I have succeeding in...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.