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

Get Attribute name

Hiya

I have a nodeReader object that I am looping through in order to retrieve
the values from the attributes, but now I need the attribute name as well,
does anyone know how to do this? I will post the code I have below:
--------------------------
'// Element example: <TextBox parent='Form' Name='txtTitle' Top='56'
Width='100' Left='152' Text='Title' />

Dim pi As System.Reflection.PropertyInfo
Dim t1 As Type = myTextBox.GetType

For i = 1 to nodeReader.AttributeCount
pi = t1.GetProperty(**Need to get the Attribute value here. Eg: Name**)
pi.SetValue(myTextBox, nodeReader.GetAttribute(i).ToString, Nothing)
Next
-------------------------

I'm sure you can see from the example, I am trying to loop through all the
attributes in my element in an XML file and set the properties of the
TextBox. I would prefer to do it this way so all I need to do in the future
is add in an appropriate attribute and value and my program will pick it up
automatically. The GetAttribute gets my value but I just need a way to get
the name of the attribute.

Thanks

Kind Regards,
Steve.
Nov 22 '05 #1
3 1761
Steve <stevea@centurion-ms_RemoveThis_.co.uk> wrote:
I have a nodeReader object that I am looping through in order to retrieve
the values from the attributes, but now I need the attribute name as well,
does anyone know how to do this? I will post the code I have below:
--------------------------
'// Element example: <TextBox parent='Form' Name='txtTitle' Top='56'
Width='100' Left='152' Text='Title' />

Dim pi As System.Reflection.PropertyInfo
Dim t1 As Type = myTextBox.GetType

For i = 1 to nodeReader.AttributeCount
pi = t1.GetProperty(**Need to get the Attribute value here. Eg: Name**)
pi.SetValue(myTextBox, nodeReader.GetAttribute(i).ToString, Nothing)
Next
-------------------------

I'm sure you can see from the example, I am trying to loop through all the
attributes in my element in an XML file and set the properties of the
TextBox. I would prefer to do it this way so all I need to do in the future
is add in an appropriate attribute and value and my program will pick it up
automatically. The GetAttribute gets my value but I just need a way to get
the name of the attribute.


You can use XmlNodeReader.MoveToAttribute and then use the Name
property, I believe. If you look at the sample code for
XmlNodeReader.HasAttributes it does the kind of thing you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Hi Jon

Your my saviour again :o)

Thank you,
Steve.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Steve <stevea@centurion-ms_RemoveThis_.co.uk> wrote:
I have a nodeReader object that I am looping through in order to retrieve the values from the attributes, but now I need the attribute name as well, does anyone know how to do this? I will post the code I have below:
--------------------------
'// Element example: <TextBox parent='Form' Name='txtTitle' Top='56'
Width='100' Left='152' Text='Title' />

Dim pi As System.Reflection.PropertyInfo
Dim t1 As Type = myTextBox.GetType

For i = 1 to nodeReader.AttributeCount
pi = t1.GetProperty(**Need to get the Attribute value here. Eg: Name**) pi.SetValue(myTextBox, nodeReader.GetAttribute(i).ToString, Nothing)
Next
-------------------------

I'm sure you can see from the example, I am trying to loop through all the attributes in my element in an XML file and set the properties of the
TextBox. I would prefer to do it this way so all I need to do in the future is add in an appropriate attribute and value and my program will pick it up automatically. The GetAttribute gets my value but I just need a way to get the name of the attribute.


You can use XmlNodeReader.MoveToAttribute and then use the Name
property, I believe. If you look at the sample code for
XmlNodeReader.HasAttributes it does the kind of thing you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #3
After you're done make sure you call MoveToElement() if you want to keep
reading the XML parse tree.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Jon

Your my saviour again :o)

Thank you,
Steve.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Steve <stevea@centurion-ms_RemoveThis_.co.uk> wrote:
I have a nodeReader object that I am looping through in order to retrieve the values from the attributes, but now I need the attribute name as well, does anyone know how to do this? I will post the code I have below:
--------------------------
'// Element example: <TextBox parent='Form' Name='txtTitle' Top='56'
Width='100' Left='152' Text='Title' />

Dim pi As System.Reflection.PropertyInfo
Dim t1 As Type = myTextBox.GetType

For i = 1 to nodeReader.AttributeCount
pi = t1.GetProperty(**Need to get the Attribute value here. Eg: Name**) pi.SetValue(myTextBox, nodeReader.GetAttribute(i).ToString, Nothing)
Next
-------------------------

I'm sure you can see from the example, I am trying to loop through all the attributes in my element in an XML file and set the properties of the
TextBox. I would prefer to do it this way so all I need to do in the future is add in an appropriate attribute and value and my program will pick
it
up automatically. The GetAttribute gets my value but I just need a way to get the name of the attribute.


You can use XmlNodeReader.MoveToAttribute and then use the Name
property, I believe. If you look at the sample code for
XmlNodeReader.HasAttributes it does the kind of thing you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 22 '05 #4

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....
0
by: Carl | last post by:
Hi, I have found a way to map attributes (columns) to column headings. But this runs really slow. Is there a way to improve it? Thanks, Carl <?xml version="1.0" encoding="utf-8" ?>...
1
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
3
by: Tony Johansson | last post by:
Hello!! Assume we have one base class called Vehicle and two derived classes called Car and Bus. I would be able to call method getName on an object of class Car or Bus and return back the name...
2
by: Isz | last post by:
Hi Group: I would like to know if it is possible to change the name of an attribute to something else. My setup is like this: I have serveral SQL tables that I nest and join so that it all...
0
by: Woody | last post by:
I need to group some attribute for use in different types, but if I nest an attributegroup inside another one I miss the nested attribute in class generated with xsd.exe. For example if I use the...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
8
by: patrizio.trinchini | last post by:
Hi All, I'would like to write an XSL transformation that changes the value of the atribute of a given element according to the value of another atttribute of the same element. For instance,...
6
by: Adam Donahue | last post by:
As an exercise I'm attempting to write a metaclass that causes an exception to be thrown whenever a user tries to access 'attributes' (in the traditional sense) via a direct reference. Consider:...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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.