serialization XML problem

A

andrewcw

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 sourcerootfolder="" manualname="">
<pmainfo pmapath=""/>
<stateaction qcdate="" qcwho=""/>
</manual>
<manual sourcerootfolder="" manualname="">
<pmainfo pmapath=""/>
<stateaction qcdate="" qcwho=""/>
</manual>
</qcsttatus>

This is my class that was generated:
//---------------------------------------------------------
---------------------
// <autogenerated>
// 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.3705.209.
//
namespace qcstatus
{
using System.Xml.Serialization;


/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="",
IsNullable=false)]
public class manual {

/// <remarks/>
public pmainfo pmainfo;

/// <remarks/>
public stateaction stateaction;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string sourcerootfolder;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string manualname;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="",
IsNullable=false)]
public class pmainfo {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string pmapath;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="",
IsNullable=false)]
public class stateaction {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string qcdate;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string qcwho;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute("qcsttatus",
Namespace="", IsNullable=false)]
public class qcsttatus {

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
("manual")]
public manual[] manual;
}
}
 
S

Swati Doshi [MSFT]

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(typeof(qcstatus.qcsttatus));
string fileName = @"c:\qcstatus.xml";
FileStream fs = new FileStream(fileName, FileMode.Open);
qcstatus.qcsttatus results = (qcstatus.qcsttatus)serializer.Deserialize(fs);
fs.Close();

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

HTH.
Thanks
Swati


--------------------
Content-Class: urn:content-classes:message
From: "andrewcw" <[email protected]>
Sender: "andrewcw" <[email protected]>
Subject: serialization XML problem
Date: Fri, 25 Jul 2003 14:51:46 -0700
Lines: 97
Message-ID: <[email protected]>
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: AcNS9vGG2cqUjZQQRwCJrXSKBhXbcQ==
Newsgroups: microsoft.public.dotnet.languages.csharp
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:171942
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.languages.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 sourcerootfolder="" manualname="">
<pmainfo pmapath=""/>
<stateaction qcdate="" qcwho=""/>
</manual>
<manual sourcerootfolder="" manualname="">
<pmainfo pmapath=""/>
<stateaction qcdate="" qcwho=""/>
</manual>
</qcsttatus>

This is my class that was generated:
//---------------------------------------------------------
---------------------
// <autogenerated>
// 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.3705.209.
//
namespace qcstatus
{
using System.Xml.Serialization;


/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="",
IsNullable=false)]
public class manual {

/// <remarks/>
public pmainfo pmainfo;

/// <remarks/>
public stateaction stateaction;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string sourcerootfolder;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string manualname;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="",
IsNullable=false)]
public class pmainfo {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string pmapath;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="",
IsNullable=false)]
public class stateaction {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string qcdate;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string qcwho;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute("qcsttatus",
Namespace="", IsNullable=false)]
public class qcsttatus {

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
("manual")]
public manual[] manual;
}
}


--

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top