object serialization

akirnarwiggerv

New Member
i've just installed the beta 2 release and am trying to get my feet wet with .net (or get my feet .wet - however you want to look at it)<BR><BR>i've experimented with a few different things and am very impressed so far<BR><BR>i'm having some trouble with serialization though. i read an article yesterday (http://www.xmlmag.com/upload/free/features/xml/2001/06jun01/dw0103/dw0103.asp) about it and thought i'd give it a try. in the article, the author uses c#, but i've tried to do the same sort of thing using vb<BR><BR>here's how i have initially set up my class (it's sitting in the server-side <script> block of my asp.net page):<BR><BR>..............................<BR>public class Hello<BR> public m_Greeting as string<BR> public property Greeting() as string<BR> get<BR> return m_Greeting<BR> end get<BR> set(byval sNewHello as string)<BR> m_Greeting = sNewHello<BR> end set<BR> end property<BR>end class<BR>..............................<BR><BR>pretty simple. according to the documentation in the beta 2 sdk, i should be able to enable serialization by doing this:<BR><BR>public class <XMLRoot(ElementName:="Hello")> Hello<BR>public <XMLAttribute(AttributeName:="Greeting")> m_Greeting as string<BR><BR>and so forth. but i'm getting the following error when i try to run it this way:<BR><BR>Compiler Error Message: BC30203: Expected an identifier.<BR><BR>and it points to this line (which is the first line where i include the serialization tags):<BR><BR>Line 9: public class <XMLRoot(ElementName:="Hello")> Hello<BR><BR>so it obviously doesn't like the fact that i put that serialization tag in front of the "Hello" identifier. also, if it makes any difference, these are the namespaces imported into my page:<BR><BR><%@Import Namespace="System"%><BR><%@Import Namespace="System.XML"%><BR><%@Import Namespace="System.XML.Serialization"%><BR><%@Import Namespace="System.IO"%><BR><%@Import Namespace="Microsoft.VisualBasic"%><BR><BR>what am i missing? is there a setting in the web.config file that needs to be changed to enable serialization? or is there a namespace i'm missing? is my syntax wrong?<BR><BR>thank you all for your helpnever mind the question above - i found out what was wrong<BR><BR>contrary to the documentation, the correct syntax for declaring the elements to be included in the serialized xml file is:<BR><BR><XMLRoot(ElementName:="Hello")> public class Hello<BR><BR>and<BR><BR><XMLAttribute(AttributeName:="Greeting")> public m_Greeting as string<BR><BR>i found out that webmethods have to be declared in a similar way (contrary to the beta 1 syntax)<BR>i.e. ...<BR><BR><WebMethod()> public function Whatever()<BR><BR>........<BR><BR>but i DO have another question<BR><BR>in order to serialize an object, one must use the XMLSerializer.Serialize() method. it's an overloaded method that requires the object you're serializing, an XMLWriter, Stream, or some other "writer" type of object<BR><BR>if i don't want to write the xml to a file, how can i use one of these writing objects to just output the xml as a string? can i do that?<BR><BR>thanks for your help!
 
Back
Top