Parsing nested Tags

Discussion in 'ASP .Net Building Controls' started by Sam, Jul 21, 2005.

  1. Sam

    Sam Guest

    Hi,

    i'm a bit stuck at the following problem and hope any of you can provide
    me wit a nice solution:

    I have a company with multiple employees.
    When creating a company control i can define a property "employee" of
    type Employee (my own created class), but that's only one employee, i
    need multiple.
    I've found an example where an Employees property is called by using the
    ParseChildren(true,"Employees"), but that means that all children are
    considered employees, but i also have other properties like "address".
    And the example defines the property as type ArrayList. How is the
    designer to know what type of tag it is (nowhere is it defined as Employee)?
    So i'm looking for a way to identify the <employee> tag when the
    employee.get() property is called.

    below a sample code of what i've tried or trying to accomplish.

    Thanks for any replies.
    Sam.


    company.aspx:
    <company>
    <address>Street 1</address>
    <employee name="john" />
    <employee name="sam" />
    </company>


    Company.vb:
    <ParseChildren(True)> _
    Public Class Company
    Inherits WebControl

    Public Property Address() As String
    ...
    End Property

    Private _elements As New ArrayList
    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public ReadOnly Property Employee() As ArrayList
    Get
    Return _employees
    End Get
    End Property

    Private _elements As Employee[]
    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public Property Employee() As Employee
    Get
    Return _employees[?]
    End Get
    Set(ByVal value As Employee)
    _employees[Employee.nr] = value
    End Set
    End Property
    End Class
    Sam, Jul 21, 2005
    #1
    1. Advertising

  2. Sam

    Teemu Keiski Guest

    "> I've found an example where an Employees property is called by using the
    > ParseChildren(true,"Employees"), but that means that all children are
    > considered employees, but i also have other properties like "address".
    > And the example defines the property as type ArrayList. How is the
    > designer to know what type of tag it is (nowhere is it defined as
    > Employee)?
    > So i'm looking for a way to identify the <employee> tag when the
    > employee.get() property is called.
    >


    Yes, instead of using ArrayList, you should have strong-typed collection in
    use. E.g collection typed for Employee object (in case for multiple possible
    employee types, typed for the common parent type if the collection stores
    them)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke
    Teemu Keiski, Jul 22, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dean H. Saxe
    Replies:
    0
    Views:
    1,008
    Dean H. Saxe
    Jan 3, 2004
  2. Rob Nicholson
    Replies:
    3
    Views:
    657
    Rob Nicholson
    May 28, 2005
  3. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    440
    Ranganath
    Oct 21, 2003
  4. Naren
    Replies:
    0
    Views:
    567
    Naren
    May 11, 2004
  5. Sam

    Parsing nested Tags

    Sam, Jul 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    90
    Teemu Keiski
    Jul 22, 2005
Loading...

Share This Page