Click here to Skip to main content
16,017,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
internal MakeModelListDTO DeserilizeXML(string xmlString, ref string returnStatus)
{
MakeModelListDTO resp = null;
string xmlString1 = @"
<env:envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://iims.services/types/">
<env:body>
<ns0:savequote_genericresponseelement xsi:type="ns0:ProposalDTO"><ns0:usercode xsi:nil="1">
<ns0:rolecode xsi:nil="1"><ns0:pretcode>100<ns0:userid xsi:nil="1">
<ns0:stakecode xsi:nil="1"><ns0:roleid xsi:nil="1"><ns0:userroleid xsi:nil="1">
<ns0:branchcode xsi:nil="1">
<ns0:preterr>Custom Error -> ORA-01403: no data found
<ns0:polbranchcode xsi:nil="1"><ns0:productname xsi:nil="1">
<ns0:policyholdercode xsi:nil="1"><ns0:eventdate>16/10/2013 16:10:15
<ns0:netpremium>765.00<ns0:termunit xsi:nil="1">
<ns0:grosspremium>680.00<ns0:policytype xsi:nil="1">
<ns0:polinceptiondate xsi:nil="1"><ns0:branchcode xsi:nil="1">
<ns0:term xsi:nil="1"><ns0:poleventeffectiveenddate xsi:nil="1">
<ns0:polstartdate xsi:nil="1"><ns0:productcode xsi:nil="1">
<ns0:policyholdername xsi:nil="1"><ns0:productid xsi:nil="1">
<ns0:servicetax>85.00<ns0:status xsi:nil="1">
<ns0:suminsured xsi:nil="1"><ns0:updatedate xsi:nil="1">
<ns0:polexpirydate xsi:nil="1"><ns0:policyid>18524965016102013
<ns0:poldetaillastupdatedate>16/10/2013 16:10:26
<ns0:quoteno>1302001310033770<ns0:policyno xsi:nil="1">
<ns0:policydetailid>18524965116102013<ns0:documentlink xsi:nil="1">
<ns0:pollastupdatedate>16/10/2013 16:10:15";
// try
// {

// XmlTextReader textReader = new XmlTextReader("C:\\XML_NIA.XML");

// List<nia> movieList = new List<nia>();

// while (textReader.Read())
// {
// NIA movie = new NIA();

// if (textReader.MoveToContent() == XmlNodeType.Element && textReader.Name == "ns0:grossPremium")
// movie.grossPremium = textReader.ReadElementString();
// if (textReader.MoveToContent() == XmlNodeType.Element && textReader.Name == "ns0:netPremium")
// movie.netPremium = textReader.ReadElementString();

// if (!String.IsNullOrEmpty(movie.grossPremium))
// movieList.Add(movie);
// }
// }

try
{
var xRoot = new System.Xml.Serialization.XmlRootAttribute();
xRoot.ElementName = "env:Envelope";
xRoot.IsNullable = true;
xRoot.Namespace = "http://schemas.xmlsoap.org/soap/envelope/";
XmlSerializer serializer = new XmlSerializer(typeof(saveQuote_GenericResponseElement), xRoot);

using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xmlString1)))
{
var doc = new System.Xml.XmlDocument();
doc.Load(stream);

var nsManager = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsManager.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");

//so I can get the actual response and not the soap body
var node = doc.SelectSingleNode("//env:Body", nsManager);

if (node != null)
{
byte[] xml = Encoding.UTF8.GetBytes(node.LastChild.InnerXml);
using (var memStream = new System.IO.MemoryStream(xml))
{
memStream.Position = 0;
saveQuote_GenericResponseElement Envelop = (saveQuote_GenericResponseElement)serializer.Deserialize(memStream); //Throws exception here
}
}
}
}

catch (Exception ex)
{
returnStatus = "Failure";
}
return resp;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900