0

Can I use XML-RPC in simulator

Hello everyone,

In order to call method from my web services, I want to use XML-RPC in my widget

I found a library "MIMIC", which supports XML-RPC for JAVASCRIPT, it works without problem in browser.

But when I tried it in simulator, it always shows ERROR "TypeError: this.xmlData has no properties in console.

In codebox, it's some functions in library mimic

CODEBOX
/**
* <p>Marshal request parameters.</p>
* @param data
* A request parameter.
* @return
* String with XML-RPC element notation.
*/
XmlRpcRequest.prototype.marshal = function(data) {
var type = XmlRpc.getDataTag(data);
var scalar_type = XmlRpc.SCALAR.replace(/\$\{TYPE\}/g, type);
var xml = "";
switch(type) {
case "struct":
var member = "";
for(var i in data) {
var value = "";
value += XmlRpc.NAME.replace("${DATA}", i);
value += XmlRpc.VALUE.replace("${DATA}", this.marshal(data[i]));
member += XmlRpc.MEMBER.replace("${DATA}", value);
}
xml = XmlRpc.STRUCT.replace("${DATA}", member);
break;
case "array":
var value = "";
for(var i = 0; i < data.length; i++) {
value += XmlRpc.VALUE.replace("${DATA}", this.marshal(data[i]));
}
xml = XmlRpc.ARRAY.replace("${DATA}", value);
break;
case "dateTime.iso8601":
xml = scalar_type.replace("${DATA}", data.toIso8601());
break;
case "boolean":
xml = scalar_type.replace("${DATA}", (data == true) ? 1 : 0);
break;
case "base64":
xml = scalar_type.replace("${DATA}", data.encode());
break;
default :
xml = scalar_type.replace("${DATA}", data);
break;
}
return xml;
};

/**
* XmlRpcResponse
* @param xml
* Response XML document.
*/
function XmlRpcResponse(xml) {
this.xmlData = xml;
};

/**
* <p>Indicate if response is a fault.</p>
* @return
* Boolean flag indicating fault status.
*/
XmlRpcResponse.prototype.isFault = function() {
return this.faultValue;
};

/**
* <p>Parse XML response to JavaScript.</p>
* @return
* JavaScript object parsed from XML-RPC document.
*/
XmlRpcResponse.prototype.parseXML = function() {
this.faultValue = undefined;
this.currentIsName = false;
this.propertyName = "";
this.params = [];
for(var i = 0; i < this.xmlData.childNodes.length; i++)
this.unmarshal(this.xmlData.childNodes[i], 0);
return this.params[0];
};



I don't think it's the problem of library, but I have no idea.

<_<Can anyone help?
Thanks!
Yinan

by
3 Replies
  • QUOTE (zhuyinan1988 @ Oct 29 2010, 02:31 AM) <{POST_SNAPBACK}>
    Hello everyone,

    In order to call method from my web services, I want to use XML-RPC in my widget

    I found a library "MIMIC", which supports XML-RPC for JAVASCRIPT, it works without problem in browser.

    But when I tried it in simulator, it always shows ERROR "TypeError: this.xmlData has no properties in console.

    In codebox, it's some functions in library mimic

    CODE
    /**
    * <p>Marshal request parameters.</p>
    * @param data
    * A request parameter.
    * @return
    * String with XML-RPC element notation.
    */
    XmlRpcRequest.prototype.marshal = function(data) {
    var type = XmlRpc.getDataTag(data);
    var scalar_type = XmlRpc.SCALAR.replace(/\$\{TYPE\}/g, type);
    var xml = "";
    switch(type) {
    case "struct":
    var member = "";
    for(var i in data) {
    var value = "";
    value += XmlRpc.NAME.replace("${DATA}", i);
    value += XmlRpc.VALUE.replace("${DATA}", this.marshal(data[i]));
    member += XmlRpc.MEMBER.replace("${DATA}", value);
    }
    xml = XmlRpc.STRUCT.replace("${DATA}", member);
    break;
    case "array":
    var value = "";
    for(var i = 0; i < data.length; i++) {
    value += XmlRpc.VALUE.replace("${DATA}", this.marshal(data[i]));
    }
    xml = XmlRpc.ARRAY.replace("${DATA}", value);
    break;
    case "dateTime.iso8601":
    xml = scalar_type.replace("${DATA}", data.toIso8601());
    break;
    case "boolean":
    xml = scalar_type.replace("${DATA}", (data == true) ? 1 : 0);
    break;
    case "base64":
    xml = scalar_type.replace("${DATA}", data.encode());
    break;
    default :
    xml = scalar_type.replace("${DATA}", data);
    break;
    }
    return xml;
    };

    /**
    * XmlRpcResponse
    * @param xml
    * Response XML document.
    */
    function XmlRpcResponse(xml) {
    this.xmlData = xml;
    };

    /**
    * <p>Indicate if response is a fault.</p>
    * @return
    * Boolean flag indicating fault status.
    */
    XmlRpcResponse.prototype.isFault = function() {
    return this.faultValue;
    };

    /**
    * <p>Parse XML response to JavaScript.</p>
    * @return
    * JavaScript object parsed from XML-RPC document.
    */
    XmlRpcResponse.prototype.parseXML = function() {
    this.faultValue = undefined;
    this.currentIsName = false;
    this.propertyName = "";
    this.params = [];
    for(var i = 0; i < this.xmlData.childNodes.length; i++)
    this.unmarshal(this.xmlData.childNodes[i], 0);
    return this.params[0];
    };



    I don't think it's the problem of library, but I have no idea.

    <_<Can anyone help?
    Thanks!
    Yinan

    Hi Yinan,

    Without knowing how you're making the call or anything else about the library, it looks like it's not receiving anything from the server and is then failing when trying to parse that.

    For example, you get a TypeError when you do the following:
    CODE
    var response = { xml: null };
    response.xml.childNodes


    - Ben
    0
  • QUOTE (Benjamin Toll @ Oct 29 2010, 03:59 PM) <{POST_SNAPBACK}>
    Hi Yinan,

    Without knowing how you're making the call or anything else about the library, it looks like it's not receiving anything from the server and is then failing when trying to parse that.

    For example, you get a TypeError when you do the following:
    CODE
    var response = { xml: null };
    response.xml.childNodes


    - Ben


    Hi Ben,
    Finally, I found the problem, i think its the problem of library.
    I just change
    CODEBOX
     for(var i = 0; i < node.childNodes.length; i++) {	
    this.unmarshal(node.childNodes[i], parent);
    }


    with

    CODEBOX
     for(var i = 0; i < node.childNodes.length; i++) {	
    this.unmarshal(node.childNodes.item(i), parent);
    }


    And it works ^^
    0
  • Yes, i encountered the exact same problem, the use of standard xml functions is a little different in the library
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets