XML pass around

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

I have an XML document that I am retrieving from a Web Service as a String.
I need to load this String into a locally accessible XMLDocument and a
custom class that I will Deserialize it into. I know how to do the
serialization, but am having trouble getting the string into the XMLReader.
Here is what I've been working with:

Dim oXML As New XmlDocument

Dim sXML As String = [WebMethod Request, returning XML]

oXML.LoadXml(sXML)

Dim xSer As New XmlSerializer(GetType(MyCustomClass))

Return xSer.Deserialize(???)

Now, I obviously need to create the XmlReader for deserailization, but how
can I get the contents of the XML document in there?
 
Instead of using the XmlDocument, load the string into the XmlReader.
Here is a sample snippet:

MyServices.MySimpleService ws = new MyServices.MySimpleService();
string xml = ws.GetXml();

XmlReader reader = new XmlTextReader( xml, XmlNodeType.Document, null
);

XmlSerializer serializer = new XmlSerializer( typeof( person ));
person p = (person)serializer.Deserialize( reader );
reader.Close();

-KIRBY
 
Wow! Works like a charm. Much better than the huge workaround I was doing
with the MemoryStream. Need help on a follow-up to this I have posted if
you have a chance to look.

Kirby Turner said:
Instead of using the XmlDocument, load the string into the XmlReader.
Here is a sample snippet:

MyServices.MySimpleService ws = new MyServices.MySimpleService();
string xml = ws.GetXml();

XmlReader reader = new XmlTextReader( xml, XmlNodeType.Document, null
);

XmlSerializer serializer = new XmlSerializer( typeof( person ));
person p = (person)serializer.Deserialize( reader );
reader.Close();

-KIRBY
--
Kirby Turner, MCSD, MCAD
www.whitepeaksoftware.com


I have an XML document that I am retrieving from a Web Service as a String.
I need to load this String into a locally accessible XMLDocument and a
custom class that I will Deserialize it into. I know how to do the
serialization, but am having trouble getting the string into the XMLReader.
Here is what I've been working with:

Dim oXML As New XmlDocument

Dim sXML As String = [WebMethod Request, returning XML]

oXML.LoadXml(sXML)

Dim xSer As New XmlSerializer(GetType(MyCustomClass))

Return xSer.Deserialize(???)

Now, I obviously need to create the XmlReader for deserailization, but how
can I get the contents of the XML document in there?
 
Point me to the follow up, i.e., posting subject, and I will see if I
can help.

Wow! Works like a charm. Much better than the huge workaround I was doing
with the MemoryStream. Need help on a follow-up to this I have posted if
you have a chance to look.

Kirby Turner said:
Instead of using the XmlDocument, load the string into the XmlReader.
Here is a sample snippet:

MyServices.MySimpleService ws = new MyServices.MySimpleService();
string xml = ws.GetXml();

XmlReader reader = new XmlTextReader( xml, XmlNodeType.Document, null
);

XmlSerializer serializer = new XmlSerializer( typeof( person ));
person p = (person)serializer.Deserialize( reader );
reader.Close();

-KIRBY
--
Kirby Turner, MCSD, MCAD
www.whitepeaksoftware.com


I have an XML document that I am retrieving from a Web Service as a String.
I need to load this String into a locally accessible XMLDocument and a
custom class that I will Deserialize it into. I know how to do the
serialization, but am having trouble getting the string into the XMLReader.
Here is what I've been working with:

Dim oXML As New XmlDocument

Dim sXML As String = [WebMethod Request, returning XML]

oXML.LoadXml(sXML)

Dim xSer As New XmlSerializer(GetType(MyCustomClass))

Return xSer.Deserialize(???)

Now, I obviously need to create the XmlReader for deserailization, but how
can I get the contents of the XML document in there?
 
Back
Top