Is there someone who see what im doing worng here?
Im trying to use this script in my asp site.
$z:value[article.number] is my art.number in my asp.
My intention when i click on my article i will see the picture.
Best Regards
Frank
<script type="text/javascript">
var symbol = "MSFT";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://produktinfo.byggtjeneste.no/ProduktInfo.asmx?op=HentBildeLenkeTyped",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
alert(xmlhttp.responseText);
var json = XMLObjectifier.xmlToJSON(xmlhttp.responseXML);
var result = json.Body[0].HentBildeLenkeTypedResponse[0].HentBildeLenkeTypedResult[0].Text;
json = XMLObjectifier.xmlToJSON(XMLObjectifier.textToXML(result));
alert(SModulNr + ' ProduktInfo: $' + json.Stock[0].Last[0].Text);
}
}
xmlhttp.setRequestHeader("SOAPAction", "http://produktinfo.byggtjeneste.no/HentBildeLenkeTyped");
xmlhttp.setRequestHeader("Content-Type", "text/xml");
var xml = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body> ' +
'<HentBildeLenkeTyped xmlns="http://produktinfo.byggtjeneste.no/"> ' +
'<sModulNr> + $z:value[article.number] + </sModulNr> '+
'<iSize>xlarge</iSize> '+
'</HentBildeLenkeTyped> ' +
'</soap:Body> ' +
'</soap:Envelope>';
xmlhttp.send(xml);
</script>
This is the orginal from my provider.
POST /ProduktInfo.asmx HTTP/1.1
Host: produktinfo.byggtjeneste.no
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HentBildeLenkeTyped xmlns="http://produktinfo.byggtjeneste.no/">
<sModulNr>string</sModulNr>
<iSize>None or small or large or xlarge or original or largeThumbnail</iSize>
</HentBildeLenkeTyped>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HentBildeLenkeTypedResponse xmlns="http://produktinfo.byggtjeneste.no/">
<HentBildeLenkeTypedResult>string</HentBildeLenkeTypedResult>
</HentBildeLenkeTypedResponse>
</soap12:Body>
</soap12:Envelope>
This line
'<sModulNr>$z:value[article.number]</sModulNr> '
is where you're going wrong. You're literally requesting the value "$z:value[article.number]" instead of the article number you want.
It's not clear exactly to me what $z is from what you've posted, but you probably want something more along the lines of
'<sModulNr>' + $z:value[article.number] + '</sModulNr>'
Related
I'm working on an outlook web add-in, I use GetItem to get the ChangeKey from the Exchange Web Service SOAP response, a value I need to compose further requests. The problem is that so far I haven't been able to get that. I have followed Find xml attribute values with javascript without success.
I'm not sure I'm able to use other external libraries since this is hosted in an office365 environment.
This is what I have been trying to do
var responseXML =
'<?xml version="1.0" encoding="utf-8"?>'+
' <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
' <s:Header>'+
' <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="3955" MinorBuildNumber="27" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'+
' </s:Header>'+
' <s:Body>'+
' <m:GetItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">'+
' <m:ResponseMessages>'+
' <m:GetItemResponseMessage ResponseClass="Success">'+
' <m:ResponseCode>NoError</m:ResponseCode>'+
' <m:Items>'+
' <t:Message>'+
' <t:ItemId Id="AAMkADZh" ChangeKey="CQABA"/>'+
' <t:Subject>the email subject</t:Subject>'+
' </t:Message>'+
' </m:Items>'+
' </m:GetItemResponseMessage>'+
' </m:ResponseMessages>'+
' </m:GetItemResponse>'+
' </s:Body>'+
'</s:Envelope>';
xmlDoc = $.parseXML(responseXML),
$xml = $(xmlDoc),
$itemId = $xml.find("ItemId");
$itemId.each(function(index, element) {
if(element.attributes["ChangeKey"]) {
console.log("ChangeKey :" + element.attributes["ChangeKey"].value);
}
});
but $itemId does not return a collection, although I'm expecting only one item, i think it doesn't hurt to leave the iteration prepared.
https://jsbin.com/matagujeye/1/edit?js,console
I found out here that I should include the name space and double escape the colons.
So the following code works:
var responseXML =
'<?xml version="1.0" encoding="utf-8"?>'+
' <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
' <s:Header>'+
' <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="3955" MinorBuildNumber="27" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'+
' </s:Header>'+
' <s:Body>'+
' <m:GetItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">'+
' <m:ResponseMessages>'+
' <m:GetItemResponseMessage ResponseClass="Success">'+
' <m:ResponseCode>NoError</m:ResponseCode>'+
' <m:Items>'+
' <t:Message>'+
' <t:ItemId Id="AAMkADZh" ChangeKey="CQABA"/>'+
' <t:Subject>the email subject</t:Subject>'+
' </t:Message>'+
' </m:Items>'+
' </m:GetItemResponseMessage>'+
' </m:ResponseMessages>'+
' </m:GetItemResponse>'+
' </s:Body>'+
'</s:Envelope>';
xmlDoc = $.parseXML(responseXML),
$xml = $(xmlDoc),
$itemId = $xml.find("t\\:ItemId");
$itemId.each(function(index, element) {
if(element.attributes["ChangeKey"]) {
console.log("ChangeKey :" + element.attributes["ChangeKey"].value);
}
});
I want to import a WSDL in XML file to my JavaScript project, which will allow my to use web client to search info.
Is there any special way to import it into my project, or do I need a package, or need to convert it into JS? I know there is a soap package in NPM, but I hope it's not the only way to do that. I've also read tutorials on W3 and still not quite sure how to manage that.
I've got something like this:
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', '127.0.0.1/start.html', true);
// build SOAP request
var sr =
'<soapenv:Envelope ' +
'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:aut="http://demo.krd.pl/Authorization" xmlns:dto="http://demo.krd.pl/Chase3.1/Dto"> ' +
'<soapenv:Header> ' +
'<aut:Authorization> '+
'<aut:AuthorizationType>LoginAndPassword</aut:AuthorizationType> ' +
'<aut:Login>login</aut:Login> ' +
'<aut:Password>password</aut:Password> ' +
'</aut:Authorization> ' +
'</soapenv:Header> ' +
'<soapenv:Body> ' +
'<dto:SearchNonConsumerRequest> ' +
'<dto:Number>24041803749</dto:Number> ' +
'<dto:NumberType>TaxId</dto:NumberType> ' +
'</dto:SearchNonConsumerRequest> ' +
'</soapenv:Body> ' +
'</soapenv:Envelope> ';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert('done. use firebug/console to see network response');
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
}
Also, where the response will be saved or will it just be posted in console?
I'm starting off with js.
I want to fetch data from a server with xml. I wonder how to send a request as, and get an anser in xml through javascript functions.
It says I need a POST-Request and send an xml in the form:
<?xml version="1.0" encoding="UTF-8"?>
<ft>
<request clientId="123" apiName="api_search_location_stops_nearby" apiVersion="2.0">
<client clientId="123"/>
<requestType>api_search_location_stops_nearby</requestType>
<outputCoords>WGS84</outputCoords>
<fromCoordName>WGS84</fromCoordName>
<fromType>coords</fromType>
<fromWgs84Lat>48.22</fromWgs84Lat>
<fromWgs84Lon>16.39</fromWgs84Lon>
</request>
</ft>
To then get an xml answer. It has 2 or 3 nodes in it, which I'm interested in. From there on, it'll be no big deal.
It is all about a strange API from the vienna public transport company:
http://akirk.github.io/Wiener-Linien-API/
I basically want to get (open)data from them.
Here:
https://techscreen.tuwien.ac.at/node/794
I found a solution for php..
My try:
// Bare bones XML writer - no attributes
function xmlElement(name,content){
var xml
if (!content){
xml = '<' + name + '>' + '</' + name + '>'
}
else {
xml = '<'+ name + '>' + content + '</' + name + '>'
}
return xml
}
function sendRequest()
{
var xmlReq
xmlReq = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
xmlReq = xmlReq + "<ft>";
xmlReq = xmlReq + "<request clientId=\"123\" apiName=\"api_get_monitor\" apiVersion=\"2.0\">";
xmlReq = xmlReq + "<client clientId=\"123\"/>";
xmlReq = xmlReq + xmlElement("requestType", "api_get_monitor");
xmlReq = xmlReq + xmlElement("monitor",
xmlElement("outputCoords", "WGS84") +
xmlElement("type","stop") +
xmlElement("name","60201040") +
xmlElement("year","2013") +
xmlElement("month","10") +
xmlElement("day","3") +
xmlElement("hour","8") +
xmlElement("minute","0") +
xmlElement("line") +
xmlElement("sourceFrom","stoplist") );
xmlReq = xmlReq + "</request>" + "</ft>";
text1.text = xmlReq;
var xhr = new XMLHttpRequest();
xhr.onload = handleRequest;
xhr.open("POST", "http://webservice.qando.at/2.0/webservice.ft"); // POST or GET
xhr.send(xmlReq);
// xhr.responseXML // this is allways null
}
function handleRequest(answer)
{
console.log(answer.responseType);
console.log(answer.responseXML);
}
The core points of my question: On my code, should there be GET or POST? Is the request built up to fit the style above (or do I need linebreaks or convert to a DOM xml thing)? How does the recieving thing work. Am I doing this right? Should the variable answer then contain the xml with the answer?
This code is somehow not working. I printed the xml-string to the console and it looks just like above (without linebreaks). But the handleRequest function doesn't print anything (it is not called at all).
Thanks in advance!
Looks like it was good allready.
I got the wrong clientID. That was basically it. Then there was just a small modification to make:
xhr.onreadystatechange = function(){ page.handleRequest(xhr); }
..to send the xmlHttpRequest over to the function. This worked for me.
Im tyring to run a basic javascript soap action on a content editor web part in sharepoint but it does not work. If I take the code out of sharepoint it runs fine in IE, why would this be?
<button onclick="doStuff()" type="submit">Send</button>
<textarea name="REQUEST_DATA" cols=120 rows=17 >
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<createModifyRequest>
<username>josephs</username>
<lookupIds>
<lookupIds>4225</lookupIds><!--firepass-->
</lookupIds>
</createModifyRequest>
</soap:Body>
</soap:Envelope>
</textarea>
<script language="javascript">
function doStuff() {
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
xmlhttp.open("POST", "http://tpdev-itreq.transpower.co.nz:7777/usr/services/CreateModifyRequest", false);
xmlhttp.setRequestHeader("SOAPAction", "createModifyRequest");
var userpass = "josephs" + ":" + "pass";
xmlhttp.setRequestHeader("Authorization", "Basic " + (userpass));
xmlhttp.setRequestHeader("Content-Type", "text/xml");
xmlhttp.send(REQUEST_DATA.value);
}
I have this XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<sizeResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sizeReturn xsi:type="xsd:int">1</sizeReturn>
</sizeResponse>
</soapenv:Body>
</soapenv:Envelope>
I want to access the 1 but .find() is not working it's giving me this error in my console
Uncaught TypeError: Object <?xml version="1.0"
encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><sizeResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><sizeReturn
xsi:type="xsd:int">0</sizeReturn></sizeResponse></soapenv:Body></soapenv:Envelope>
has no method 'getElementsByTagName'
How can I access it otherwise using jQuery or JS (if there's a way using an Xpath plugin please provide the Xpath expression) ?
Thank you
Try this:
var xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><sizeResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><sizeReturn xsi:type="xsd:int">0</sizeReturn></sizeResponse></soapenv:Body></soapenv:Envelope>',
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc );
console.log($xml.find("sizeReturn").html());
Read Docs http://api.jquery.com/jQuery.parseXML/
Fiddle: http://jsfiddle.net/cY5xZ/
Can you try this one.
<script>
function GetVal()
{
var txt = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><sizeResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><sizeReturn xsi:type="xsd:int">0</sizeReturn></sizeResponse></soapenv:Body></soapenv:Envelope>';
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc = parser.parseFromString(txt, "text/xml");
var v = xmlDoc.getElementsByTagName("sizeReturn")[0].childNodes[0].nodeValue;
alert("t" +v);
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(txt);
}
}
</script>
Cheers :)