Get Attribute name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    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.Reflecti on.PropertyInfo
    Dim t1 As Type = myTextBox.GetTy pe

    For i = 1 to nodeReader.Attr ibuteCount
    pi = t1.GetProperty( **Need to get the Attribute value here. Eg: Name**)
    pi.SetValue(myT extBox, nodeReader.GetA ttribute(i).ToS tring, 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.


  • Jon Skeet [C# MVP]

    #2
    Re: Get Attribute name

    Steve <stevea@centuri on-ms_RemoveThis_. co.uk> wrote:[color=blue]
    > 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.Reflecti on.PropertyInfo
    > Dim t1 As Type = myTextBox.GetTy pe
    >
    > For i = 1 to nodeReader.Attr ibuteCount
    > pi = t1.GetProperty( **Need to get the Attribute value here. Eg: Name**)
    > pi.SetValue(myT extBox, nodeReader.GetA ttribute(i).ToS tring, 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.[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Steve

      #3
      Re: Get Attribute name

      Hi Jon

      Your my saviour again :o)

      Thank you,
      Steve.

      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1a89a6 c86945845098a05 8@msnews.micros oft.com...[color=blue]
      > Steve <stevea@centuri on-ms_RemoveThis_. co.uk> wrote:[color=green]
      > > I have a nodeReader object that I am looping through in order to[/color][/color]
      retrieve[color=blue][color=green]
      > > the values from the attributes, but now I need the attribute name as[/color][/color]
      well,[color=blue][color=green]
      > > 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.Reflecti on.PropertyInfo
      > > Dim t1 As Type = myTextBox.GetTy pe
      > >
      > > For i = 1 to nodeReader.Attr ibuteCount
      > > pi = t1.GetProperty( **Need to get the Attribute value here. Eg:[/color][/color]
      Name**)[color=blue][color=green]
      > > pi.SetValue(myT extBox, nodeReader.GetA ttribute(i).ToS tring, Nothing)
      > > Next
      > > -------------------------
      > >
      > > I'm sure you can see from the example, I am trying to loop through all[/color][/color]
      the[color=blue][color=green]
      > > 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[/color][/color]
      future[color=blue][color=green]
      > > is add in an appropriate attribute and value and my program will pick it[/color][/color]
      up[color=blue][color=green]
      > > automatically. The GetAttribute gets my value but I just need a way to[/color][/color]
      get[color=blue][color=green]
      > > the name of the attribute.[/color]
      >
      > You can use XmlNodeReader.M oveToAttribute and then use the Name
      > property, I believe. If you look at the sample code for
      > XmlNodeReader.H asAttributes it does the kind of thing you want.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Klaus H. Probst

        #4
        Re: Get Attribute name

        After you're done make sure you call MoveToElement() if you want to keep
        reading the XML parse tree.


        --
        _______________ _____
        Klaus H. Probst, MVP
        Great prices on a large selection of domains. Find the pefect domain for your new startup.



        "Steve" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
        news:%23wUd2yl6 DHA.1968@TK2MSF TNGP11.phx.gbl. ..[color=blue]
        > Hi Jon
        >
        > Your my saviour again :o)
        >
        > Thank you,
        > Steve.
        >
        > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
        > news:MPG.1a89a6 c86945845098a05 8@msnews.micros oft.com...[color=green]
        > > Steve <stevea@centuri on-ms_RemoveThis_. co.uk> wrote:[color=darkred]
        > > > I have a nodeReader object that I am looping through in order to[/color][/color]
        > retrieve[color=green][color=darkred]
        > > > the values from the attributes, but now I need the attribute name as[/color][/color]
        > well,[color=green][color=darkred]
        > > > 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.Reflecti on.PropertyInfo
        > > > Dim t1 As Type = myTextBox.GetTy pe
        > > >
        > > > For i = 1 to nodeReader.Attr ibuteCount
        > > > pi = t1.GetProperty( **Need to get the Attribute value here. Eg:[/color][/color]
        > Name**)[color=green][color=darkred]
        > > > pi.SetValue(myT extBox, nodeReader.GetA ttribute(i).ToS tring, Nothing)
        > > > Next
        > > > -------------------------
        > > >
        > > > I'm sure you can see from the example, I am trying to loop through all[/color][/color]
        > the[color=green][color=darkred]
        > > > 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[/color][/color]
        > future[color=green][color=darkred]
        > > > is add in an appropriate attribute and value and my program will pick[/color][/color][/color]
        it[color=blue]
        > up[color=green][color=darkred]
        > > > automatically. The GetAttribute gets my value but I just need a way to[/color][/color]
        > get[color=green][color=darkred]
        > > > the name of the attribute.[/color]
        > >
        > > You can use XmlNodeReader.M oveToAttribute and then use the Name
        > > property, I believe. If you look at the sample code for
        > > XmlNodeReader.H asAttributes it does the kind of thing you want.
        > >
        > > --
        > > Jon Skeet - <skeet@pobox.co m>
        > > http://www.pobox.com/~skeet
        > > If replying to the group, please do not mail me too[/color]
        >
        >[/color]


        Comment

        Working...