Deserialize an XmlNode, HOW?

Lets say I have an XmlNode created by:


Dim cs As XmlSerializer = New XmlSerializer(GetType(String))
Dim cms As MemoryStream = New MemoryStream
cs.Serialize(cms, "This is a test")
cms.Position = 0

Dim cd As XmlDocument = New XmlDocument
cd.Load(cms)
Dim contents As XmlNode = ImportNode(cd.DocumentElement, True)


how to I deserialize this node again...I've tried something like:

Dim cs As XmlSerializer = New XmlSerializer(GetType(String))
Dim ms As MemoryStream = New MemoryStream
Dim xw As XmlWriter = New XmlTextWriter(ms, Nothing)
c.WriteContentTo(xw)
xw.Flush()
ms.Position = 0
Dim s As Object = cs.Deserialize(ms)


However it dowsn't really work....any help would be greatly appreciated

TIA

S�ren 


0
smolesen (2)
9/19/2005 11:58:08 AM
dotnet.xml 7266 articles. 0 followers. Follow

0 Replies
699 Views

Similar Articles

[PageSpeed] 24

Reply:

Similar Artilces:

XmlSchemaValidator and XmlSerializer.Deserialize()
In an application which uses an XML file, I wish to use XmlSchemaValidator class to validate this file against the XSD file.. In the example of msdn, ( http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator(VS.80).aspx ) , before initialising the XmlSchemaValidator, XmlSerializer is initialised. I saw that if there is a node or attribute which is not valid (to xml schema), the method XmlSerializer.Deserialize() launches an exception. It means that before validating this file ( or stream ) its already controlled by Deserialize method. I wish to know what is the n...

C#: How to deserialize an object to a string
I want to know how can i deserialize an object to a string, instead of a file as below:ShoppingList myList = new ShoppingList(); myList.AddItem( new Item( "eggs",1.49 ) ); myList.AddItem( new Item( "ground beef",3.69 ) ); myList.AddItem( new Item( "bread",0.89 ) ); // Serialization XmlSerializer s = new XmlSerializer( typeof( ShoppingList ) ); TextWriter w = new StreamWriter( @"c:\list.xml" ); s.Serialize( w, myList ); w.Close(); // Deserialization ShoppingList newList; TextReader r = new StreamReader( "list.xml" ); newList = (ShoppingList)s....

XML Deserialization
Hello Guys, I have tried to use the xsd.exe tool to generate a class for the following Oracle-generated xml sample but always fail to get it right when I try to change oracle xml elements names to the class's names, specifically I'm not sure how to do it for the ROWSET and ROW part of it. Being very new to the serialization/deserialization business I'm sure this is very easy to implement for someone with a bit of more knowledge of it, can some help me please. I have created 2 classes for for Department and Employee: [XmlRoot("ROWSET")] class Dep...

deserializing
I'm trying to deserialize my xml type as an array w/o a declared namespace, but none of the Serialization Attribute classes help. Where can I find info on how to build a deserializer that will create arrays? I think you will need to create a wrapper class and suck the array out of that wrapper. "jsh02_nova@hotmail.com" <jsh02novahotmailcom@discussions.microsoft.com> wrote in message news:89A83E5F-EC8D-4EB2-A737-5FFF86FCCC14@microsoft.com... > I'm trying to deserialize my xml type as an array w/o a declared > namespace, > but none of the Serialization Att...

XML Deserialization Issue
Hello All, I am having some trouble deserializing some xml into a series of objects that are part of a web service proxy. I know the XML is valid, and the objects are up to date (the xml instance doc validates against the original scheme, which is current with the WSDL). The issue looks familiar, its identical to one that I have seen when the xmlserializer chokes on a namespace. In past instances with simple XML docs I was able to get things working by supplying the Deserialize method a default namespace, but in this case I have 3 namespaces, and no default. Any ideas as to how I would go ...

Deserialization
I have an xml file containing some stuff. I use xsd to generate a schema and again to create classes from the schemas. added using System, System.IO; added [Serializable] to all classes added namespace ROC added deserialize() method as follows to AWLR2 class: public AWLR2 deserialize(string xmlString) { AWLR2 awlr2; try { StringReader sr = new StringReader(xmlString); XmlSerializer ser = new XmlSerializer(this.GetType()); awlr2=(AWLR2)ser.Deserialize(sr); } catch(Exception ex) { System.Diagnostics.EventLog.WriteEntry("BizTalk Redemptions", ex.ToString()); throw ex; } ...

How to deserialize with several namespaces
Hello, I'm trying to deserialize an RSS feed that can contains 2 namespaces. FOr example, it can contain a tag <image> and/or <itunes:images>. I couldn't figure out how to get both. This simplified extract of code does not work: [XmlRoot(ElementName = "rss")] public class RSSFeed { [...] [XmlElement("image", typeof(Image))] public Image Picture = new Image(); [XmlElement("image", typeof(Image), Namespace="http://www.itunes.com/dtds/podcast-1.0.dtd")] public Image iPicture = new Image(); public RSSFeed Load(Strea...

Deserialize xml
Hi, I am getting an error when I try to deserialize a XML file into a object with a apostrpohe in the data. Works fine when I remove the apostrophe. Any thoughts???? Rotsey wrote: > Hi, > > I am getting an error when I try to deserialize a XML file into a object > with a > apostrpohe in the data. > > Works fine when I remove the apostrophe. > > Any thoughts???? Can you specify error details, code snippet and some sample data for which you are getting error ? ...

Deserialize Attribute with a Namespace
I have an xml document like so... <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions"> <channel> <title></title> <link></link> <description></description> ... </channel> </rss> What .NET XmlAttribute properties do I need to use in order to deserialize the namespace value? I tried this and a bunch of other options, but nothing seems to work. [XmlAttribute("ng", "http://newsgator.com/schema/exten...

XML deserializer
(Type your message here) -------------------------------- From: Rohit All, I have an xml that does not have any namespace associated with= any of the nodes but the element in the corresponding class= which has been generated using XSDObjectGen=2Eexe has= namespaces=2ESo after deserializing the XML to the class object,= my class object does not have any items in it=2E ----------------------- Posted by a user from =2ENET 247 (http://www=2Edotnet247=2Ecom/) <Id>sknZU2tYjEuSn48n2yL3ig=3D=3D</Id> ...

Deserializing problem
I'm trying to deserialize an xml file created in php. I created the class in .Net to hold the information and created a test object with data, ran it through serializing to a memory stream and deserialized it as well as reading it into a string to check the formatting. This worked fine. But when I tried deserializing the xml generated by the php file it throws an invalid xml exception. When I output the two streams for comparision they appear identical with the exception of carriage return-linefeeds plus some whitespace in between tags in the .net generated xml. Any ideas what I'm mis...

Cannot implicitly convert type 'System.Xml.XmlNode' to 'System.Xml.XmlAttribute'
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value = ddDes.SelectedItem.ToString(); xmlDocument.Save("abc.xml"); However, I get the foll. error: Cannot implicitly convert type 'System.Xml.XmlNode' to 'System.Xml.XmlAttribute' What code should be modified so that the error is resolved. Thanks. > XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); should be XmlAttribute xmlAttrib = (XmlAttribut...

Deserialize elements to hashtable
I am bit stuck here (it's monday and I am having probs concentrating). I have the following Xml file: <?xml version="1.0" encoding="utf-8" ?> <preferences> <groups> <group name="group1"> <settings> <setting name="setting1" value="value1" /> <setting name="setting2" value="value2" /> </settings> </group> <group name="group2"> ...

Using XmlRootAttribute for deserialization
I've seen this come up before, but in my case, things are a little more complex, and I'm having a tough time figuring out how to set an element name that works. I have a configuration file that is my serialized object (I'm using a customer deserializer to add some more XAML-like capabilities): <AppConfigObject> <RuntimeType:Kernel xmlns:RuntimeType="MyNamespace.DefaultKernel, Kernel"/> </AppConfigObject> public class AppConfigObject { [XmlElement] public Kernel {...} } Problem I have is deserializing the child node <Kernel> because it al...

Problems with Deserialization...
Hi, I'm having problems with some very simple deserialization code and would appreciate it very much if I could get some help here. The following is the code: ========================================================= XmlReader reader = new XmlTextReader("test.xml"); XmlValidatingReader vr = new XmlValidatingReader(reader); try { while (vr.Read()){} XmlSerializer xs = new XmlSerializer(typeof(Event)); ev = (Event)xs.Deserialize(reader); } catch (Exception e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine(ev.Config.User); <<<< This ...

Deserializing an array
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in the data but I can't figure out where the data is in the resulting array. Most of the relevant code is below. When I run the code to desrialize I get no errors but if I try to look at some of the data via the command window I get errors such as this: ?judges2.Judges(0).JudgeFirstName Index '0' for dimension '0' is out of range. What am I missing here? Wayne =============...

Deserializing XML
I am trying to use XmlSerializer to serialize the XML string into an object. I used the XML schema definition to generate the code for the corresponding class (using xsd.exe). The top level class has references to objects of other classes that are defined in the same schema. I am trying to deserialize the XML string into an object of the class that was generated as explained above. Here is my code: XML string is in this.textBox1.Text. private void button1_Click(object sender, System.EventArgs e) { string strReqInstance = this.textBox1.Text; XmlTextReader reqInstanceReader = new XmlText...

deserialize to a property
I am using web services to request some DTO-style objects from a service layer. I'd like to data bind them to some UI controls, but the properties are deserialized as fields, which aren't bindable. What're my options for working around this, other than rewriting the generated code? That really isn't an option, because there are too many types. Thanks, Shawn ...

Deserialize from SelectSingleNode
Is it possible to pull a single node (element) out of a complex XML file, using SelectSingleNode(), and then deserialize that node to an object? Could someone please post, or point me to, a simple, but complete example? "Geoff" <geoffbishop@gmail.com> wrote in message news:db109b3f.0411171811.19f5ad33@posting.google.com... > Is it possible to pull a single node (element) out of a complex XML > file, using SelectSingleNode(), and then deserialize that node to an > object? Yes, if your XML document looks like this, for example, <MyDocument> <ComplexIn...

Deserialize an XmlNode, HOW?
Lets say I have an XmlNode created by: Dim cs As XmlSerializer = New XmlSerializer(GetType(String)) Dim cms As MemoryStream = New MemoryStream cs.Serialize(cms, "This is a test") cms.Position = 0 Dim cd As XmlDocument = New XmlDocument cd.Load(cms) Dim contents As XmlNode = ImportNode(cd.DocumentElement, True) how to I deserialize this node again...I've tried something like: Dim cs As XmlSerializer = New XmlSerializer(GetType(String)) Dim ms As MemoryStream = New MemoryStream Dim xw As XmlWriter = New XmlTextWriter(ms, Nothing) c.WriteContentTo(xw) xw.Flush() ms.Position = ...

deserialize an attribute
Hi, I have an xml document that looks like this: <Order> ... <StatusCd Desc="Hold">H</StatusCd> ... </Order> And I would like to deserialize it so that the "Desc" attribute is copied to a member variable: class Order { //Should contain "hold" after deserialization public string StatusDesc } How can I accomplish this? Thanks, Gabe ---------------------- The opinions expressed here are mine and not those of my employer Gabe Moothart wrote: > How can I accomplish this? Use the xsd.exe tool to infer an XSD sche...

XML Deserialization (IXmlSerializable implementation)
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary implementations cannot be serialized, I had to take matters into my own hands by implementing a wrapper over the Hashtable which implemted IXmlSerializable. I called it XmlHashtable. It has, among other convenience methods, a method called ReadXml(XmlReader) and a method called WriteXml(XmlWriter). This is an abstract class which also contains two abstract properties which return strings so I co...

deserialize a collection
I'm writing a class in C# .... I have a collection calls Reports made up of Report objects. I'm trying to deserialize an XML file that looks like : <Reports> <Report> <Title>some title</Title> <Notes> some notes </Notes> </Report> <Report> blah blah blah </Report> </Reports> ------------------------------------------------------------------- I want to be able to deserialize the file in the Reports collection constructor and build the Report objects on the fly. The only examples I'...

XML deserialization from string
Hi, I have an XSD and created a VB.NET class file from it. When I have an XML file (conforming to the schema), it is straight forward to deserialize using the class file. I am looking for ways to deserialize when I have the XML as a string and not in a file. Writing the string to a file and deserializing from the file might have an adverse effect on the performance. Anyone know of a good method to do this? Any help will be appreciated. Thanks, Sampath. Use a StringReader to read the file and wrap that in an XmlTextReader. -- This posting is provided "AS IS" with no warranties,...

Deserialization question
I have a simple question. I am using the XSD.exe to generate my C# classes. When I go to deserialize I do this: ( where qcmoverini is the root XML element ). <qcmoverini> <paths transactionpath="c:\movertest\qctransactionlog.xml" statuspath="c:\movertest\qcstatus.xml" destpath="c:\movertest\data\"/> <intervals filecontention="4" waitcycle="15"/> </qcmoverini> But if I try to reach directly into an internal class I always error. like my class paths. It shows up on intellisense as if it should work. try { T...