{"action":"created","issue":{"url":"https://api.github.com/repos/yaronn/ws.js/issues/11","labels_url":"https://api.github.com/repos/yaronn/ws.js/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/yaronn/ws.js/issues/11/comments","events_url":"https://api.github.com/repos/yaronn/ws.js/issues/11/events","html_url":"https://github.com/yaronn/ws.js/issues/11","id":64117619,"number":11,"title":"What is the path to soap element (sorry for unexpected close)","user":{"login":"minyixie","id":11154360,"avatar_url":"https://avatars.githubusercontent.com/u/11154360?v=3","gravatar_id":"","url":"https://api.github.com/users/minyixie","html_url":"https://github.com/minyixie","followers_url":"https://api.github.com/users/minyixie/followers","following_url":"https://api.github.com/users/minyixie/following{/other_user}","gists_url":"https://api.github.com/users/minyixie/gists{/gist_id}","starred_url":"https://api.github.com/users/minyixie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minyixie/subscriptions","organizations_url":"https://api.github.com/users/minyixie/orgs","repos_url":"https://api.github.com/users/minyixie/repos","events_url":"https://api.github.com/users/minyixie/events{/privacy}","received_events_url":"https://api.github.com/users/minyixie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-03-24T22:41:06Z","updated_at":"2015-03-27T02:50:36Z","closed_at":null,"body":"The original question is\r\n\r\n\"In the following sample, I am confused what is the path to the soap elements\r\n\r\n//add attachment to the soap request\r\nws.addAttachment(ctx, \"request\", \"//*[local-name(.)='File1']\", \r\n\"me.jpg\", \"image/jpeg\")\r\n\r\nwhat is the \"//*[local-name(.)='File1']\", how can I use it or replace it by what?\"\r\n\r\nand the reply from yaronn is\r\n\r\n\"Hi\r\n\r\nThe File1 refers to the File1 element in the SOAP message that appears before:\r\n\r\n              var request = '<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">' +\r\n                '<s:Body>' +\r\n                  '<EchoFiles xmlns=\"http://tempuri.org/\">' +                        \r\n                      '<File1 />' +\r\n                  '</EchoFiles>' +\r\n                '</s:Body>' +\r\n              '</s:Envelope>\r\nIf you have a sample SOAP request you want to send then check which element should contain the attachment and use it in the xpath.\""},"comment":{"url":"https://api.github.com/repos/yaronn/ws.js/issues/comments/86795796","html_url":"https://github.com/yaronn/ws.js/issues/11#issuecomment-86795796","issue_url":"https://api.github.com/repos/yaronn/ws.js/issues/11","id":86795796,"user":{"login":"minyixie","id":11154360,"avatar_url":"https://avatars.githubusercontent.com/u/11154360?v=3","gravatar_id":"","url":"https://api.github.com/users/minyixie","html_url":"https://github.com/minyixie","followers_url":"https://api.github.com/users/minyixie/followers","following_url":"https://api.github.com/users/minyixie/following{/other_user}","gists_url":"https://api.github.com/users/minyixie/gists{/gist_id}","starred_url":"https://api.github.com/users/minyixie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minyixie/subscriptions","organizations_url":"https://api.github.com/users/minyixie/orgs","repos_url":"https://api.github.com/users/minyixie/repos","events_url":"https://api.github.com/users/minyixie/events{/privacy}","received_events_url":"https://api.github.com/users/minyixie/received_events","type":"User","site_admin":false},"created_at":"2015-03-27T02:50:36Z","updated_at":"2015-03-27T02:50:36Z","body":"Hi Yaronn,\n\nIt is so appreciate  for your help and explanation, I will try your code\nand feedback what will happen.\n\nRegards\nMinyi\n\nOn Thu, Mar 26, 2015 at 11:40 PM, Yaron Naveh <notifications@github.com>\nwrote:\n\n> hi\n>\n> this looks like an issue with the xpath engine.\n> this is the response:\n>\n> <s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>\n> <get_image_pngResponse xmlns=\"http://tempuri.org/\"><get_image_pngResult><xop:Include\n> href=\"cid:http://tempuri.org/1/635629682617340181\"\n> xmlns:xop=\"http://www.w3.org/2004/08/xop/include\"/></get_image_pngResult>\n> </get_image_pngResponse></s:Body></s:Envelope>\n>\n> the href is:\n>\n> cid:http://tempuri.org/1/635629682617340181\n>\n> the xpath is built using the method encodeURIComponent so it is:\n>\n> //*[@href='cid:http%3A%2F%2Ftempuri.org%2F1%2F635629682617340181']//parent::*\n>\n> but the xpath engine does not know to match the escaped characters (%2F\n> --> /)\n> the library has been tested on xml's where the response used the escaped\n> characters as well so this was not an issue. I am not sure if the current\n> response is valid or not, but it should be supported either way.\n>\n> *a quick workaround:*\n>\n> use the new handlers order (mtom first, than http).\n> also add this in the beginning of your application:\n>\n> encodeURIComponent = function(s) {return s}\n>\n> (it will override the encodeURIComponent global method - it will not work\n> if you need it in other places. you could replace it just before you call\n> the ws and return it back after if you want).\n>\n> so the full code will be:\n>\n> var http = require(\"http\");\n> var url = require(\"url\");\n>\n> encodeURIComponent = function(s) {return s}\n>\n> var ws = require('ws.js'),\n>    Http = ws.Http,\n>    Mtom = ws.Mtom;\n>\n> var message = '<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n> xmlns:tem=\"http://tempuri.org/\">' +\n>       '<soapenv:Header/>' +\n>       '<soapenv:Body>' +\n>         '<tem:get_image_png>' +\n>           '<!--Optional:-->' +\n>           '<tem:access_key>UxKjqyuQUANqAC8eNVG6EOjs2FBHZ6N41239</tem:access_key>' +\n>           '<!--Optional:-->' +\n>           '<tem:name>girl</tem:name>' +\n>           '<!--Optional:-->' +\n>           '<tem:image_name>girl1</tem:image_name>' +\n>         '</tem:get_image_png>' +\n>       '</soapenv:Body>' +\n>    '</soapenv:Envelope>';\n>\n> var ctx =  { request: message\n>            , url: \"https://www.aercloud.net/webapi?wsdl\"\n>            , action: \"http://tempuri.org/IISMWebAPI/get_image_png\"\n>            , contentType: \"text/xml; chartset=utf16\"\n>            , contentEncoding: \"text/xml\"\n>            };\n>\n> //add attachment to the soap request\n> //ws.addAttachment(ctx, \"request\",\"//*[local-name(.)='get_image_pngResult']\",\"me.png\",'image/png');\n>\n> var handlers =  [new Mtom(), new Http()];\n>\n> ws.send(handlers, ctx, function(ctx) {\n>     //read an attachment from the soap response\n>       //console.log(ctx);\n>       //console.log(\"done\")\n>       var file = ws.getAttachment(ctx, \"response\", \"//*[local-name(.)='get_image_pngResult']\")\n>       require('fs').writeFileSync(\"result.png\", file)\n>       //console.log(file)\n> })\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/yaronn/ws.js/issues/11#issuecomment-86494882>.\n>\n"}}