c# Soap in xml file -
i need create .xml files store in folder computer come , pick up. have figure out except how following included in file:
<soap:envelope xlmns=(i have namespace text figured out)>   <soap:body> . . .   </soap:body> </soap:envelope>   how incorporate soap:body , soap:envelope elements file??
here code
  string[] source = file.readalllines(sallfilename);   file.delete(sallfilename);   //  create message type 3   xelement msg3 = new xelement(@"soap:envelope",       str in source       let fields = str.split(',')       select new xelement(@"soap:body",           new xelement("report_info",               new xelement("message_no", temp3),               new xelement("message_type", "3"),               new xelement("batch_no", sidataforcsv[0]),               new xelement("product_datum",                   new xelement("test_data",                       new xelement("norm_type", fields[3]),                       new xelement("sample_id", fields[4]),                       new xelement("result_source", fields[5]),                       new xelement("entered_by", fields[6]),                       new xelement("reported", fields[7]),                       new xelement("result", fields[8])                       )                   )               )           )       );   the error message says "can't have : in name"
the soap: namespace prefix, have handle differently when building xelement - can't put "soap:element name" in there.
you can use xnamespace set xmlns namespace, , prepend element name.  use xattribute set namespace prefix.
try this:
xnamespace soap = "http://www.w3.org/2003/05/soap-envelope"; xelement msg3 = new xelement(soap + @"envelope",                     new xattribute(xnamespace.xmlns + "soap", "http://www.w3.org/2003/05/soap-envelope"),                       str in source                       let fields = str.split(',')                       select new xelement(soap + @"body",   this give you
<soap:envelope xmlns=http://www.w3.org/2003/05/soap-envelope>   <soap:body>   </soap:body> </soap:envelope>   added
to add xml declaration can switch xelement xdocument , use xdeclaration property:
xnamespace soap = "http://www.w3.org/2003/05/soap-envelope"; xdocument msg3 = new xdocument("1.0", "utf-8", "yes"),                    new xelement(soap + @"envelope",                       new xattribute(xnamespace.xmlns + "soap", "http://www.w3.org/2003/05/soap-envelope"),                         str in source                         let fields = str.split(',')                         select new xelement(soap + @"body",   this give xdocument xml declaration this:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>   if @ in debugger, may not see xml declaration if @ xdeclaration property in debugger or save file (via save(string filename) method will.
Comments
Post a Comment