Sunday 15 September 2013

xml - Expression is of type "FileName", which is not a collection type -



xml - Expression is of type "FileName", which is not a collection type -

alright, since wasn't able comment , inquire help on original question found i'm making new 1 (original: how value specific node in xml file?)

these 2 classes have; 1 construction of xml file, sec list in it:

public class fellow member public naam string public kills integer public deaths integer public kd integer end class public class tabel <xmlelement("member")> _ public members list(of member) end class

this code executes it:

dim serializer xmlserializer = new xmlserializer(gettype(tabel)) dim tabel tabel = ctype(serializer.deserialize(file.openread("c:\members.xml")), tabel) each fellow member member in tabel dim kills integer = member.kills next

it should loop through xml file , should, errors out on "tabel" lastly variable in each loop. saying: look of type 'vbtest.tabel', not collection type.

thanks in advance!

you need declare members property new object or error. omit <xmlelement("member")> if outer xml element hold collection.

public class tabel '<xmlelement("member")> public property members new list(of member) end class

output:

<?xml version="1.0" encoding="utf-8"?> <tebel xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <members> <member> <id>1</id> </member> </members>

if adding them need variable outside loop.

dim kills integer each fellow member member in tabel.members kills += member.kills next

xml vb.net serialization deserialization

No comments:

Post a Comment