Im getting the following error when running my application: Additional information: Error in line 2 position 64. Expecting element 'CustomerLeads' from namespace 'http://www.w3.org/2001/XMLSchema-instance'.. Encountered 'Element' with name 'CustomerLeads', namespace ''.
I dont understand why I am getting this error message because as you can see from the XML 'CustomerLeads' is included within the XML. If I take out the namespace the file will not read the Elements. Including the namespace seems to work but cant seem to figure out why I am getting this error. And how I can add the namespace without getting this error?
<?xml version="1.0" encoding="UTF-8"?>
<CustomerLeads xsi:noNamespaceSchemaLocation="BasicCustomerLead.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CustomerLead>
<FirstName>Paul</FirstName>
<LastName>Smith</LastName>
<Email>[email protected]</Email>
</CustomerLead>-<CustomerLead>
<FirstName>Nicole</FirstName>
<LastName>Farhi</LastName>
<Email>[email protected]</Email>
</CustomerLead>-<CustomerLead>
<FirstName>Raf</FirstName>
<LastName>Simons</LastName>
<Email>[email protected]</Email>
</CustomerLead>
</CustomerLeads>
Code:
namespace Customer
{
[DataContract(Name = "CustomerLeads", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public class CustomerLeads
{
[DataMember()]
public string FirstName { get; set; }
[DataMember()]
public string LastName { get; set; }
[DataMember()]
public string EmailAddress { get; set; }
public CustomerLeads unSortedLeads(string xmFilelPath)
{
// doc.Load("C:/Users/Admin/Downloads/potentialcustomers.xml");
ICollection<CustomerLeads> deserializedPerson;
CustomerLeads lead;
FileStream fs = new FileStream(xmFilelPath, FileMode.Open);
XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
DataContractSerializer ser = new DataContractSerializer(typeof(CustomerLeads));
lead = (CustomerLeads)ser.ReadObject(reader, true);
reader.Close();
fs.Close();
FirstName = lead.FirstName.ToString();
// foreach(CustomerLeads leads in deserializedPerson.)
return lead;
}
}
}