XML prefix deserialization problems

  • Thread starter Thread starter Evzhel
  • Start date Start date
E

Evzhel

Guest
There is a xml file, where one tag and several attributes has prefix. So I can't get value in this case.

xml:

<?xml version="1.0" encoding="utf-16"?>
<Response xmlns:xsd="XML Schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Body xmlns="urn:types.nmvs.eu:v2.0">
<Product>
<ProductCode p6:scheme="AT85" xmlns:p6="urn:types.nmvs.eu:v2.0">03838989662123</ProductCode>
<Batch>
<Id>TEST7957</Id>
<ExpDate>210500</ExpDate>
</Batch>
</Product>
<Pack p5:sn="0DPTT705Y" p5:state="INACTIVE" xmlns:p5="urn:types.nmvs.eu:v2.0">
<p5:Reason>OUTOFORDER</p5:Reason>
</Pack>
</Body>
</Response>


classes:

public class Reason
{
[XmlElement]
public string Value { get; set; }
}
public class Batch
{
[XmlElement("Id")]
public string Id { get; set; }

[XmlElement("ExpDate")]
public string ExpDate { get; set; }
}

public class ProductCode
{
[XmlAttribute("Scheme", Namespace = "")]
public string scheme { get; set; }

[XmlText]
public string Value { get; set; }
}
public class Product
{
[XmlElement("ProductCode")]
public ProductCode ProductCode { get; set; }

[XmlElement("Batch")]
public Batch Batch { get; set; }

[XmlElement("Reason", Namespace = "urn:types.nmvs.eu:v2.0")]
public Reason Reason { get; set; }
}

public class Body
{
[XmlElement("Product")]
public Product Product { get; set; }
}

[XmlRoot("Response")]
public class Response
{
[XmlAttribute("xsd", Namespace = "XML Schema")]
public string Xsd { get; set; }

[XmlElement("Body", Namespace = "urn:types.nmvs.eu:v2.0")]
public Body Body { get; set; }

}


code:

Response response = new Response();
XmlSerializer serializer = new XmlSerializer(typeof(Response));
StreamReader reader = new StreamReader("test.xml");
response = (Response)serializer.Deserialize(reader);


Problems with next attributes: p6:scheme="AT85", p5:sn="0DPTT705Y" p5:state="INACTIVE" and with tag: <p5:Reason>OUTOFORDER</p5:Reason>

Value for this element and attributes in result object is Null. What I need to do, to get this values?

Continue reading...
 
Back
Top