I am trying to deserialize this xml:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
yahoo:count="10" yahoo:created="2012-02-20T19:07:02Z" yahoo:lang="en-US">
<results>
<a href="/dir/index?sid=396545299">Books & Authors</a>
<a href="/dir/index?sid=396545374">Dancing</a>
<a href="/dir/index?sid=396546034">Genealogy</a>
<a href="/dir/index?sid=396545298">History</a>
<a href="/dir/index?sid=396545310">Other - Arts & Humanities</a>
<a href="/dir/index?sid=396545300">Performing Arts</a>
<a href="/dir/index?sid=396545231">Philosophy</a>
<a href="/dir/index?sid=2115500137">Poetry</a>
<a href="/dir/index?sid=396546419">Theater & Acting</a>
<a href="/dir/index?sid=396545309">Visual Arts</a>
</results>
</query>
This is by the way a xml that yahoo api returnes when queried for categories and subcategories.
This code that is supposed to deserialize it:
string query_string = "some_url";
HttpWebRequest request = HttpWebRequest.Create
(query_string) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
System.Xml.Serialization.XmlSerializer serializer = new
System.Xml.Serialization.XmlSerializer(typeof(queryA));
queryA Q = (queryA)serializer.Deserialize(reader); // THIS IS WHERE THE EXCEPTION IS THROWN
reader.Close();
}
and I get an exception saying: There is an error in XML document (2, 2).
Exception details:
"<query xmlns=''> was not expected."
Here's the class:
namespace Yahoo_answers_tool {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class queryA {
private queryResultsA[] resultsField;
private string countField;
private string createdField;
private string langField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("a", typeof(queryResultsA), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public queryResultsA[] results {
get {
return this.resultsField;
}
set {
this.resultsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://www.yahooapis.com/v1/base.rng")]
public string count {
get {
return this.countField;
}
set {
this.countField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://www.yahooapis.com/v1/base.rng")]
public string created {
get {
return this.createdField;
}
set {
this.createdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://www.yahooapis.com/v1/base.rng")]
public string lang {
get {
return this.langField;
}
set {
this.langField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class queryResultsA {
private string hrefField;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string href {
get {
return this.hrefField;
}
set {
this.hrefField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class NewDataSetA {
private queryA[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("query")]
public queryA[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
}
Any Ideas?