When i run the following code to serialize the facbook users, the code generated is something like:
<?xml version="1.0"?>
<ArrayOfUser
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="fbapp">
<user>
<user xmlns="http://api.facebook.com/1.0/">
<about_me />
</user>
</user>
</ArrayOfUser>
but when i try to read it by de-serializing it, the user (which is generated using a schema) will have the root as <user>
instead of <user xmlns="http://api.facebook.com/1.0/">
tag breaking everything.
public static List<facebook.Schema.user> ReadFromFile(String filename)
{
Stream str = File.OpenRead(filename);
XmlSerializer formatter = new XmlSerializer(typeof(List<facebook.Schema.user>));
List<facebook.Schema.user> users = (List<facebook.Schema.user>) formatter.Deserialize(str);
str.Close();
return users;
}
public static void WriteToFile(List<facebook.Schema.user> users, String filename)
{
Stream str;
// ...open...
XmlSerializer formatter = new XmlSerializer(typeof(List<facebook.Schema.user>));
formatter.Serialize(str, users);
str.Close();
}
EDIT: The class i am trying to view is here: Source at Codeplex (look for the user class)
Also, the problem i feel is that the serialization is adding an extra <user>
tag for every list element. I tried to serialize a single user object and even that is wrapped in a <user>
tag. So i get something like:
<?xml version="1.0"?>
<user>
<user xmlns="http://api.facebook.com/1.0/">
...
</user>
</user>
instead of
<?xml version="1.0"?>
<user xmlns="http://api.facebook.com/1.0/">
...
</user>