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. Deserialize xml file having namespaces

Deserialize xml file having namespaces

Scheduled Pinned Locked Moved C#
comxmljsonhelp
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.
  • N Offline
    N Offline
    NarVish
    wrote on last edited by
    #1

    I would like to deserialize the below xml file. I used the below code. It returned exception:"There is an error in XML document (0, 0)."

    XmlReader txtReader = XmlReader.Create(reader.BaseStream);
    XmlSerializer deSerializer = new XmlSerializer(typeof(ResponseType));
    ResponseType resp = (ResponseType)deSerializer.Deserialize(txtReader);

    Note:reader.BaseStream contains the below xml xml file: ------------

    112200eed1b00e42a061

    entry in xsd file : -------------------

    Class file ----------

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xyz.com/datacq/xx/service")]
    [System.Xml.Serialization.XmlRootAttribute("addMemberResponse", Namespace = "http://xyz.com/datacq/xx/service", IsNullable = false)]
    public partial class ResponseType
    {
    private string info;
    public string Info
    {
    get
    {
    return this.info;
    }
    set
    {
    this.info = value;
    }
    }
    }

    L 1 Reply Last reply
    0
    • N NarVish

      I would like to deserialize the below xml file. I used the below code. It returned exception:"There is an error in XML document (0, 0)."

      XmlReader txtReader = XmlReader.Create(reader.BaseStream);
      XmlSerializer deSerializer = new XmlSerializer(typeof(ResponseType));
      ResponseType resp = (ResponseType)deSerializer.Deserialize(txtReader);

      Note:reader.BaseStream contains the below xml xml file: ------------

      112200eed1b00e42a061

      entry in xsd file : -------------------

      Class file ----------

      [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
      [System.SerializableAttribute()]
      [System.Diagnostics.DebuggerStepThroughAttribute()]
      [System.ComponentModel.DesignerCategoryAttribute("code")]
      [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xyz.com/datacq/xx/service")]
      [System.Xml.Serialization.XmlRootAttribute("addMemberResponse", Namespace = "http://xyz.com/datacq/xx/service", IsNullable = false)]
      public partial class ResponseType
      {
      private string info;
      public string Info
      {
      get
      {
      return this.info;
      }
      set
      {
      this.info = value;
      }
      }
      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm thinking that the element name in the XML file is "info" whereas the property name in the class is "Info" ... You can only deserialize properties; "info" is not a property.

      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