PC Review


Reply
Thread Tools Rate Thread

deserializing and XML file [.csdl file EntityFramework]

 
 
VRSki@newsgroup.nospam
Guest
Posts: n/a
 
      7th Apr 2009
I am trying to deserialize a .csdl file, generated by EdmGen.exe (part of MS
Entity Framework). The file itself is an xml file, even though it has a .csdl
extension. But unfortunately, the second line contains an element that
doesn't seem to be supported by XML serializer:

------- XML start --------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="SomeProject" Alias="Self"
xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<Element1>data</Element1>
</Schema>
------- XML end --------------------------------------------------------

Here is the code I use to deserialize this fileL:

// read in the file into the stream
System.IO.Stream oCsdlXml = ....

// create the serializer -- Schema class contains Element1 member
XmlSerializer oSerializer = new XmlSerializer(typeof(Schema));

// this line below throws exception:
Schema oSchema = oSerializer.Deserialize(oCsdlXml) as Schema;

Exception: "There is an error in XML document (2, 2)"
Internal Exception: "<Schema
xmlns='http://schemas.microsoft.com/ado/2006/04/edm'> was not expected."

If I take out this part from the xml file -- it all works and my Element1 is
properly deserialized:

xmlns="http://schemas.microsoft.com/ado/2006/04/edm"


Is that a truly invalid XML construct? Is there any way to deserialize this
using attribute overrides?

Thank you for your help,
VR
 
Reply With Quote
 
 
 
 
not_a_commie
Guest
Posts: n/a
 
      7th Apr 2009
Can you try the same thing with the DataContractSerializer?
 
Reply With Quote
 
VRSki@newsgroup.nospam
Guest
Posts: n/a
 
      9th Apr 2009
Tried that. Here is the new error message (no inner exception).

Error in line 1 position 93. Expecting element 'Schema' from namespace
'http://schemas.datacontract.org/2004/07/XmlSchemaDeserializerTest'..
Encountered 'Element' with name 'Schema', namespace
'http://schemas.microsoft.com/ado/2006/04/edm'.

Thanks,
VR


"not_a_commie" wrote:

> Can you try the same thing with the DataContractSerializer?
>

 
Reply With Quote
 
not_a_commie
Guest
Posts: n/a
 
      9th Apr 2009
The data type that you are trying to serialize into -- it has a
different namespace declared for the 'Schema' element than what is
declared in your XML itself.
 
Reply With Quote
 
VRSki@newsgroup.nospam
Guest
Posts: n/a
 
      9th Apr 2009
Could you please help me out here? I am not sure what you mean by "it has a
different namespace declared for the 'Schema'"..

The element I am trying to serialize the stream to IS Schema:

XmlSerializer oSerializer = new XmlSerializer(typeof(Schema));

And Schema is a pretty straight-forward class:

namespace SomeNamespace
{
[Serializable]
public class Schema
{
public Schema() {}
public string Element1() {get;set;}
}
}

What namespace should I change in Schema class to make it work? Are you
saying namespace SomeNamespace should be renamed?

Thanks again for your help.
VR

"not_a_commie" wrote:

> The data type that you are trying to serialize into -- it has a
> different namespace declared for the 'Schema' element than what is
> declared in your XML itself.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to: Questions About EDM and CSDL CharlesRCaplan@gmail.com Microsoft Dot NET Framework 3 5th Apr 2008 09:10 AM
Where to: Questions About EDM and CSDL CharlesRCaplan@gmail.com Microsoft ADO .NET 3 5th Apr 2008 09:10 AM
Deserializing XML file Sriranjan Microsoft Dot NET Framework 2 6th May 2006 04:18 AM
Deserializing an XML (soap) file on a pocket pc into a hashtable Carsten Microsoft Dot NET Compact Framework 0 1st May 2006 03:52 PM
Problem deserializing file from asp.net =?Utf-8?B?U3RldmUgQnVnZGVu?= Microsoft ASP .NET 2 21st Aug 2005 02:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 PM.