c# - Problems formatting xml string after removing SOAP envelope -


bear me here i'm extremely new web programming , xml.

i'm creating mvc 4 app pulls information external database , displays in table compare xml files sent out insurance ratings. displayed table fine, xml looked chunky wanted format in better way. had bulky soap envelope around removed but, xml string extracted 1 loooong line cannot seem break , format in manners internet suggested.

here example of xml in soap envelope (edited):

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:iaax="http://www.ibm.com/ima/iaa/iaaxml" xmlns:soap="soap" xmlns:ext="urn:blah">   <soapenv:header>     <wsse:security soap:mustunderstand="1" xmlns:wsse="http://docs...">       <wsse:usernametoken wsu:id="usernametoken-9999999" xmlns:wsu="http://docs...">         <wsse:username>{0}</wsse:username>         <wsse:password type="http://docs.......">{1}</wsse:password>         <wsse:nonce>#########==</wsse:nonce>         <wsu:created>2009-10-14t16:22:08.102z</wsu:created>       </wsse:usernametoken>     </wsse:security>   </soapenv:header>   <soapenv:body>     <iaax:genericproxyservice>       <requestheader>         <iaax:id>_pnumda</iaax:id>         <iaax:cmdtype>request</iaax:cmdtype>         <iaax:cmdmode>alwaysrespond</iaax:cmdmode>         <iaax:echoback>false</iaax:echoback>         <iaax:servicecontext>           <keepalive>false</keepalive>           <channelname>dspr</channelname>           <vendorid />           <debug>false</debug>           <trace>false</trace>         </iaax:servicecontext>       </requestheader>       <targetaction>calculate</targetaction>       <marketableproduct>foo</marketableproduct>       <requestdata><![cdata[<tns:calculateasdf xmlns:tns="http://www.blah.com"><calculate><policy></policy><policynumber>2</policynumber><agentid>aa1000</agentid><marketableproduct>home</marketableproduct><items><item><state>pa</state><unittype>dwelling</unittype></item></items></calculate></tns:calculateasdf>]]></requestdata>     </iaax:genericproxyservice>   </soapenv:body> </soapenv:envelope> 

to take out did this:

{   ....     list<service> list = session.service.tolist();                 list<service> searchlist = new list<service>();                 searchlist.addrange(                     list.where(                         x =>                         x.serviceid.equals(srrid1) ||                         x.serviceid.equals(srrid2)));      foreach (var s in searchlist)     {       xdocument doc = xdocument.parse(s.xmltext);            foreach (xelement e in doc.descendants("requestdata"))           {              string newxml = (string)e;               service.xmltext = newxml;           }     }     return view(searchlist.defaultifempty()); } 

this how xml looks on screen (edited):

 <tns:calculateasdf xmlns:tns="http://www.blah.com"><calculate><policy></policy><policynumber>2</policynumber><agentid>aa1000</agentid><marketableproduct>home</marketableproduct><items><item><state>pa</state><unittype>dwelling</unittype></item></items></calculate></tns:calculateasdf> 

...yet displays in 1 big long string stretching table.

i tried break elements down following this post, didn't work...

foreach (var s in searchlist) {     xdocument doc = xdocument.parse(s.xmltext);      var dict =                 doc.element("calculate")                    .elements()                    .todictionary(x => x.name.localname, x => x.value);      string policynum = dict["policynumber"];     s.xmltext = policynum; } 

i'm getting similar error poster after implemented solution tried use inner tag , didn't work. trying use calculateasdf doesn't work either... both throw exception:

object reference not set instance of object.

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.nullreferenceexception: object reference not set instance of object.

i think think calculateasdf doesn't work because of tns:

so... i'm at. i'm sorry constructed poor, i'm learning go. on how either break xml down readable xml or way take xml , store , display variables like:

edit:

 * policynumber: 2  * agentid: zz1234  * marketableproduct: home  * state: pa  * unittype: dwelling 

it appreciated. after have xml displaying right, i'm going attempt create diff tool , have show changed between ratings. appreciate constructive input. if needs clarified, please let me know.

ps (sorry post isn't formatted well, not used asking questions on here yet)


Comments