Parsing nested Tags

S

Sam

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
 
T

Teemu Keiski

"> 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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top