serialization XML problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andrewcw

    #1

    serialization XML problem

    There is an error in XML document (1, 2).
    I used XML spy to create the XML and XSD. When I asked to
    have the XML validated it said it was OK.

    I used the .net SDK to generate the class. I have done
    this before but this time I have no idea why I am getting
    the error. Any ideas ?? THANKS !

    <qcsttatus>
    <manual sourcerootfolde r="" manualname="">
    <pmainfo pmapath=""/>
    <stateaction qcdate="" qcwho=""/>
    </manual>
    <manual sourcerootfolde r="" manualname="">
    <pmainfo pmapath=""/>
    <stateaction qcdate="" qcwho=""/>
    </manual>
    </qcsttatus>

    This is my class that was generated:
    //---------------------------------------------------------
    ---------------------
    // <autogenerate d>
    // This code was generated by a tool.
    // Runtime Version: 1.0.3705.209
    //
    // Changes to this file may cause incorrect behavior
    and will be lost if
    // the code is regenerated.
    // </autogenerated>
    //---------------------------------------------------------
    ---------------------

    //
    // This source code was auto-generated by xsd,
    Version=1.0.370 5.209.
    //
    namespace qcstatus
    {
    using System.Xml.Seri alization;


    /// <remarks/>
    [System.Xml.Seri alization.XmlRo otAttribute(Nam espace="",
    IsNullable=fals e)]
    public class manual {

    /// <remarks/>
    public pmainfo pmainfo;

    /// <remarks/>
    public stateaction stateaction;

    /// <remarks/>
    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    public string sourcerootfolde r;

    /// <remarks/>
    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    public string manualname;
    }

    /// <remarks/>
    [System.Xml.Seri alization.XmlRo otAttribute(Nam espace="",
    IsNullable=fals e)]
    public class pmainfo {

    /// <remarks/>
    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    public string pmapath;
    }

    /// <remarks/>
    [System.Xml.Seri alization.XmlRo otAttribute(Nam espace="",
    IsNullable=fals e)]
    public class stateaction {

    /// <remarks/>
    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    public string qcdate;

    /// <remarks/>
    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    public string qcwho;
    }

    /// <remarks/>
    [System.Xml.Seri alization.XmlRo otAttribute("qc sttatus",
    Namespace="", IsNullable=fals e)]
    public class qcsttatus {

    /// <remarks/>
    [System.Xml.Seri alization.XmlEl ementAttribute
    ("manual")]
    public manual[] manual;
    }
    }
  • Swati Doshi [MSFT]

    #2
    RE: serialization XML problem

    Hi Andrew,

    Firstly, let me confirm: The XML deserialization is giving you this error right? What is the type that you are sending to the XMLSerializer?
    Since the root is qcstatus, sending that should work. It did when I tried. I got the same error you did if I set the type as 'manual' instead.
    Maybe that's what's going wrong?...

    So, doing the below on your xml file should work:

    XmlSerializer serializer = new XmlSerializer(t ypeof(qcstatus. qcsttatus));
    string fileName = @"c:\qcstatus.x ml";
    FileStream fs = new FileStream(file Name, FileMode.Open);
    qcstatus.qcstta tus results = (qcstatus.qcstt atus)serializer .Deserialize(fs );
    fs.Close();

    (remember to put try catch blocks for File exception or deserialization exception)

    HTH.
    Thanks
    Swati


    --------------------[color=blue]
    >Content-Class: urn:content-classes:message
    >From: "andrewcw" <andrew.c.watts @boeing.com>
    >Sender: "andrewcw" <andrew.c.watts @boeing.com>
    >Subject: serialization XML problem
    >Date: Fri, 25 Jul 2003 14:51:46 -0700
    >Lines: 97
    >Message-ID: <04c501c352f6$f 1869f70$a101280 a@phx.gbl>
    >MIME-Version: 1.0
    >Content-Type: text/plain;
    > charset="iso-8859-1"
    >Content-Transfer-Encoding: 7bit
    >X-Newsreader: Microsoft CDO for Windows 2000
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >Thread-Index: AcNS9vGG2cqUjZQ QRwCJrXSKBhXbcQ ==
    >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
    >Path: cpmsftngxa06.ph x.gbl
    >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1719 42
    >NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
    >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
    >
    >There is an error in XML document (1, 2).
    >I used XML spy to create the XML and XSD. When I asked to
    >have the XML validated it said it was OK.
    >
    >I used the .net SDK to generate the class. I have done
    >this before but this time I have no idea why I am getting
    >the error. Any ideas ?? THANKS !
    >
    ><qcsttatus>
    > <manual sourcerootfolde r="" manualname="">
    > <pmainfo pmapath=""/>
    > <stateaction qcdate="" qcwho=""/>
    > </manual>
    > <manual sourcerootfolde r="" manualname="">
    > <pmainfo pmapath=""/>
    > <stateaction qcdate="" qcwho=""/>
    > </manual>
    ></qcsttatus>
    >
    >This is my class that was generated:
    >//---------------------------------------------------------
    >---------------------
    >// <autogenerate d>
    >// This code was generated by a tool.
    >// Runtime Version: 1.0.3705.209
    >//
    >// Changes to this file may cause incorrect behavior
    >and will be lost if
    >// the code is regenerated.
    >// </autogenerated>
    >//---------------------------------------------------------
    >---------------------
    >
    >//
    >// This source code was auto-generated by xsd,
    >Version=1.0.37 05.209.
    >//
    >namespace qcstatus
    >{
    >using System.Xml.Seri alization;
    >
    >
    >/// <remarks/>
    >[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="",
    >IsNullable=fal se)]
    >public class manual {
    >
    > /// <remarks/>
    > public pmainfo pmainfo;
    >
    > /// <remarks/>
    > public stateaction stateaction;
    >
    > /// <remarks/>
    > [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    > public string sourcerootfolde r;
    >
    > /// <remarks/>
    > [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    > public string manualname;
    >}
    >
    >/// <remarks/>
    >[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="",
    >IsNullable=fal se)]
    >public class pmainfo {
    >
    > /// <remarks/>
    > [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    > public string pmapath;
    >}
    >
    >/// <remarks/>
    >[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="",
    >IsNullable=fal se)]
    >public class stateaction {
    >
    > /// <remarks/>
    > [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    > public string qcdate;
    >
    > /// <remarks/>
    > [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    > public string qcwho;
    >}
    >
    >/// <remarks/>
    >[System.Xml.Seri alization.XmlRo otAttribute("qc sttatus",
    >Namespace="" , IsNullable=fals e)]
    >public class qcsttatus {
    >
    > /// <remarks/>
    > [System.Xml.Seri alization.XmlEl ementAttribute
    >("manual")]
    > public manual[] manual;
    >}
    >}
    >[/color]


    --

    This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified
    at http://www.microsoft.com/info/cpyright.htm

    Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they
    originated.

    Comment

    Working...