I have a web service that hit by the client and returns an XML string of serialized XML object.
I have this class that serialized to XML:
public class ControlValveResultModel
{
public string Selection { get; set; }
public int PipeCount { get; set; }
public int ControlValveCount { get; set; }
public int ServiceValveCount { get; set; }
}
Here the function that makes serialization of the object before it sent to yhe client:
public string ToXML<T>(T dataToSerialize)
{
try
{
var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(typeof(T));
serializer.Serialize(stringwriter, dataToSerialize);
return stringwriter.ToString();
}
catch
{
throw;
}
}
Here how looks object in the client:
"<?xml version="1.0" encoding="utf-16"?>
<ControlValveResultModel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Selection>184028.884942584,664923.573252621,183875.392224311,664759.166484197</Selection>
<PipeCount>78</PipeCount>
<ControlValveCount>4</ControlValveCount>
<ServiceValveCount>26</ServiceValveCount>
</ControlValveResultModel>"
In client-side, I try to convert object above to this:
"<?xml version="1.0" encoding="utf-16"?>
<ControlValveResultModel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Selection>184028.884942584,664923.573252621,183875.392224311,664759.166484197</Selection>
<PipeCount>78</PipeCount>
<ControlValveCount>4</ControlValveCount>
<ServiceValveCount>26</ServiceValveCount>
</ControlValveResultModel>"
I tried this to decode:
var stringXML = decodeURIComponent(data)
But stringXML is not decoded.
How can I decode the XML above and get value?