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

retrieving an attribute from a node in a nodelist

Hi,
I can't seem to get the syntax correct. I have an xmlnodelist full of
elements called "file". Each file has an attribute called "ID". If I just
want to get, say, the ID of the second file in the list, how do I write this?

Thanks!!!
Mel
Nov 17 '05 #1
3 3424
There is a GetAttribute method of the XmlElement class you can call.

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
Hi,
I can't seem to get the syntax correct. I have an xmlnodelist full of
elements called "file". Each file has an attribute called "ID". If I
just
want to get, say, the ID of the second file in the list, how do I write
this?

Thanks!!!
Mel

Nov 17 '05 #2
Mel,

You should be able to use an XPath query, like so:

file[@ID]

You can use the SelectSingleNode method (or other select node methods)
to select the attribute(s).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
Hi,
I can't seem to get the syntax correct. I have an xmlnodelist full of
elements called "file". Each file has an attribute called "ID". If I
just
want to get, say, the ID of the second file in the list, how do I write
this?

Thanks!!!
Mel

Nov 17 '05 #3
here is an example from my code
private void LoadExtensions( string url, bool merging,bool isString )

{

ArrayList extens = new ArrayList();

XmlTextReader reader;

if(!isString)

{

Stream stream = MakeStream(url); // this bascially opens the file that has
xml

reader = new XmlTextReader(stream);//this reads the stream (file)

}

else

{

reader = new XmlTextReader(url); //if its url then i don t need to open the
file etc

}

XmlDocument doc = new XmlDocument();

doc.Load(reader);

XmlNodeList nodeLst = doc.GetElementsByTagName("WAMiConf"); //top node
if( nodeLst.Count != 1 )

throw new Exception("Invalid XML data. A single WAMiConf tag is required.");

mErrors = new ArrayList();

foreach( XmlNode topNode in nodeLst )

{

foreach( XmlNode extNode in topNode.ChildNodes )

{

if( extNode.Name == "Extensions" )

extens.AddRange( ParseExtensions( extNode ) );

}

}
}
private ArrayList ParseExtensions( XmlNode extenNode )

{

ArrayList extens = new ArrayList();

foreach( XmlNode node in extenNode.ChildNodes )

{

if( node.Name.ToLower() == "extension" )

{

InternalExtension extension = new InternalExtension();

// Look for optional "group" and "maxoccurs" attributes

if( node.Attributes["group"] != null )

extension.GroupName = node.Attributes["group"].Value;

foreach( XmlNode child in node.ChildNodes )

{

if( child.Name.ToLower() == "name" )

extension.Name = child.InnerText;

if( child.Name.ToLower() == "number" )

extension.ExtensionNumber = child.InnerText;

}
}

return extens;

}

forgive me if there are syntax or mismatching braces i just copied and
cleaned up the code for simplicity, otherwise it would be two pages long and
hard to understand.

HTH
Nov 17 '05 #4

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

Similar topics

8
by: chris yoker via DotNetMonster.com | last post by:
hiya, I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method. This nodeList is taken from a repetitive, uniform xml doc. I can successfully append a child node at the correct...
3
by: chris yoker via DotNetMonster.com | last post by:
hi, I have an xmlFile <code> <rows> <row> <PRODUCT-TYPE>bike</PRODUCT-TYPE> <PRODUCT-DATE>01/01/2004</PRODUCT-DATE> <ADDED-NODE>"blah"<ADDED-NODE /> </row>
6
by: Grant | last post by:
I have this simple xml file which wont ever get beyong 3 nodes deep. I need to get the value of the child node of any node with an id of '63'. So fir instance I would be returned 'False' from the...
4
by: ryu | last post by:
Hi all, I have a xml document where I have to replace the value of node type that is text. For example, if the value of a node whose type is 'text' is 'Toyota', I would like it to be...
2
by: William | last post by:
Have somebody a brilliant idea how to remove a nodelist in a XML document? (With C#) I have this xml file,I want delete the stock nodelist when an user don't have permissions to see stocklist of...
1
by: D Ratcliffe | last post by:
Hello In a nutshell, I am looping through an XML document in a for loop, and I want to insert a given value as an element to each tag as I go along. i.e.: for (int i=0; i <...
2
by: K B | last post by:
I bit new to this. My xml files contains the following nodes: <root> <WI Title="Test1"> <Role Name="Legal"/> <Role Name="PM"/> </WI> <WI Title="Test1"> <Role Name="Legal"/> <Role...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: krunaldsoni | last post by:
Let me give you my problem statement: <positiondata > <touchpad reportedFingers="2" /> <timestamp user="Dev" time="1252088979018" /> <reported2d x="447" y="232" z="31" w="1" finger="0"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.