DeSerialize and Serialize from XML to XML

How to make use of XML_CONTROL class

Page 1 of 1

2 Replies - 4477 Views - Last Post: 14 January 2011 - 10:10 AM Rate Topic: -----

#1 RaeYoung  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 13-January 11

DeSerialize and Serialize from XML to XML

Posted 13 January 2011 - 02:08 PM

I am trying to read in an XML document, add a record with a tag for the filename and write to a different XML document.

I have been told I must use serialization.

I generated an XSD from the file I am using for input. From the XSD, I created the VB class using XSD.EXE for the incoming XML.

I added the required record and tag for the filename and changed the name of the root record and created a second VB class for the outgoing XML.

I added the VB class for the incoming and outgoing XML to my project.

To deserialize and serialize the XML, I found the code here:
http://www.dreaminco...ation-in-vbnet/

I assume the first thing I need to do is Deserialize the XML file. To try to use the code, I put the following in my programme to read the incoming XML file:
s_text = XML_CONTROL.FromXml(l_s_SourcePath & l_s_Srcfilename, GetType(Envelope))



l_s_SourcePath is the full path of the folder containing the file
l_s_Srcfilename is the name of the file
Envelope is the root record of the incoming XSD

I get an error on the following line from the XML_CONTROL class:
obj = ser.Deserialize(xmlReader)


eException.Message "There is an error in XML document (1, 1)." String

Following the function line by line
 Dim ser As XmlSerializer
 ser = New XmlSerializer(ObjType)
 Dim stringReader As StringReader
 stringReader = New StringReader(Xml) ‘XML is filename including full path
 Dim xmlReader As XmlTextReader
 xmlReader = New XmlTextReader(stringReader) ‘stringreader is {System.IO.StringReader}
 Dim obj As Object
 obj = ser.Deserialize(xmlReader) ‘xmlReader is {System.Xml.XmlTextReader}



I think that once I get to the obj = ser.Deserialize line that xmlReader should have the contents of the file, but when I do a watch on:
xmlReader.Item(0).ToString

I get the ArgumentOutOfRange exception.

Any suggestions as to where I go from here?

Is This A Good Question/Topic? 0
  • +

Replies To: DeSerialize and Serialize from XML to XML

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,083
  • Joined: 02-July 08

Re: DeSerialize and Serialize from XML to XML

Posted 13 January 2011 - 02:38 PM

Not necessarily, use the XmlDocument and you can make a node with the ImportNode method on the first Xmldocument.
Was This Post Helpful? 0
  • +
  • -

#3 RaeYoung  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 13-January 11

Re: DeSerialize and Serialize from XML to XML

Posted 14 January 2011 - 10:10 AM

Looks like the original code may have been missing a read. When I changed the StringReader to StreamReader and added a xmlReader.Read() before the Dim OBJ As Object, the deserialize worked.
Was This Post Helpful? -1
  • +
  • -

Page 1 of 1