Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. help with Deserialize a string problem in c#

help with Deserialize a string problem in c#

Scheduled Pinned Locked Moved C#
helpcsharpxmljsonquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drey1
    wrote on last edited by
    #1

    :confused:I have a problem with the Deserialize a xml string. I have a object I serialize: MemoryStream buffer = new MemoryStream(); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(myobject)); xmlSerializer.Serialize(buffer, schedule); if I Deserialize the object after this code line, it works fine. But if I store the xml in code it Deserialize it gives me an error. XmlDocument doc = new XmlDocument(); doc.Load(buffer); string xml = doc.OuterXml; XmlTextReader xmlreader = new XmlTextReader(xml); schedule = (ScheduleDefinition) serializer.Deserialize(xmlreader); I need the xml string as a parameter, so i need to be able to convert it back into the object. But I always get the message: {"There is an error in XML document (1, 426)." } Any other suggestions to accomplish this? X|

    J 1 Reply Last reply
    0
    • D drey1

      :confused:I have a problem with the Deserialize a xml string. I have a object I serialize: MemoryStream buffer = new MemoryStream(); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(myobject)); xmlSerializer.Serialize(buffer, schedule); if I Deserialize the object after this code line, it works fine. But if I store the xml in code it Deserialize it gives me an error. XmlDocument doc = new XmlDocument(); doc.Load(buffer); string xml = doc.OuterXml; XmlTextReader xmlreader = new XmlTextReader(xml); schedule = (ScheduleDefinition) serializer.Deserialize(xmlreader); I need the xml string as a parameter, so i need to be able to convert it back into the object. But I always get the message: {"There is an error in XML document (1, 426)." } Any other suggestions to accomplish this? X|

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #2

      It sounds like your trying to serialize a string that contains xml using an xml serializer. I've never tried that before, but I have the suspicion that you might have some problems with that. Primarily, if your xml string contains the xml file header (i.e. ), and its embedded in the middle of another xml document, then you will get an error when the parser tries to read that "string". You can only have at the top of an xml document, and it can not exist anywhere else. XML inside XML might be your problem (although I can't guarantee it).

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups