Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

XML Deserialization problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zemnon@gmail.com - 06 Jul 2006 19:45 GMT
Hello guys,

Here is a part of XML I am getting from a huge XML file:

<Task xmlns="http://al-lighting.com/alcheck/Namespace/AL">
 <Name>String</Name>
 <Script>
   <ScriptFilename>String</ScriptFilename>
   <ResultFilename>String</ResultFilename>
   <Reportstyles>
     <Name>String</Name>
     <ReportstyleFilename>String</ReportstyleFilename>
     <ReportFilenameExtension>String</ReportFilenameExtension>
     <SchemaFilename>String</SchemaFilename>
   </Reportstyles>
 </Script>
</Task>

here is a class that I was generated with xsd.exe according to my xsd
file:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://mynamespace")]
[System.Xml.Serialization.XmlRoot("Task")]
public partial class ALTask
{

   private ALTaskName nameField;

   private ALScript scriptField;

   private ALTaskComment commentField;

   /// <remarks/>
   public ALTaskName Name {
       get {
           return this.nameField;
       }
       set {
           this.nameField = value;
       }
   }

   /// <remarks/>
   public ALScript Script {
       get {
           return this.scriptField;
       }
       set {
           this.scriptField = value;
       }
   }

   /// <remarks/>
   public ALTaskComment Comment {
       get {
           return this.commentField;
       }
       set {
           this.commentField = value;
       }
   }
}

and I am trying to deserialize it to the class structure using this
code:
           string xml = nodes.Current.OuterXml.ToString();
           StringReader reader = new StringReader(xml);
           XmlSerializer xs = new XmlSerializer(typeof(ALTask));
           xs.Serialize(aa, testTask);
           ALTask task = (ALTask) xs.Deserialize(reader);

The error shows that the {"<Task xmlns='http://mynamespace'> was not
expected."}

Does anyone know what the problem is? Because I also tried tp
deserialize the string "<Task><Name>String</Name></Task>" and it
works....

Please help, because I am very confused on this stage.

I will appreciate any help.

Best regards,
Zemnon
Marcin Hoppe - 07 Jul 2006 07:35 GMT
[cut]
> The error shows that the {"<Task xmlns='http://mynamespace'> was not
> expected."}

Please note that namespaces don't match. This one (denoted by an
attribute in the class generated by the xsd.exe tool) is different from
the one in the XML document. I have been experiencing deserialization
problems related to XML namespaces quite often.

Best regards!
Marcin
zemnon@gmail.com - 07 Jul 2006 10:25 GMT
Hello Marcin,

Thank you for your quick reply.

I have changed the namespace only in company issues in my post and not
in the code. I confirm that the Namespace is the same for both ->
Deserialization class and string with xml data.

Best regards,
Zemnon

> [cut]
> > The error shows that the {"<Task xmlns='http://mynamespace'> was not
[quoted text clipped - 7 lines]
> Best regards!
> Marcin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.