Converts a JSON object to an XML or soap string.

Source: Internet
Author: User

<SCRIPT>
// Convert a JSON object to XML
Function toxml (OBJ ){
VaR xml = "";
For (var k in OBJ ){
VaR v = OBJ [k];
If (typeof (v )! = "Object "){
XML + = "<" + K + ">" + V + "</" + K + "> ";
} Else {
XML + = "<" + K + "> ";
XML + = toxml (v );
XML + = "</" + K + "> ";
}
}
Return XML;
}

// Construct a soap call String
// Name: Method Name
// ARGs: attached JSON Parameter
// Ns: namespace OF THE METHOD
Function tosoap (name, argS, NS)
{
VaR MSG = '';
MSG + = '<v: envelope \ r \ n ';
MSG + = 'xmlns: I = "http://www.w3.org/2001/xmlschema-instance%22/r/n ';
MSG + = 'xmlns: D = "http://www.w3.org/2001/xmlschema%22/r/n ';
MSG + = 'xmlns: c = "http://schemas.xmlsoap.org/soap/encoding/42422/r/n ';
MSG + = 'xmlns: V = "http://schemas.xmlsoap.org/soap/envelope/42422/r/n ';
MSG + = '> \ r \ n ';
MSG + = '<v: Header/> \ r \ n ';
MSG + = '<v: Body> \ r \ n ';
MSG + = '<' + name + 'xmlns = "'+ NS +'" id = "O0" C: Root = "1"> \ r \ n ';
MSG + = ''+ toxml (ARGs) +" \ r \ n ";
MSG + = '</' + name + '> \ r \ n ';
MSG + = '</V: Body> \ r \ n ';
MSG + = '</V: envelope> \ r \ n ';
Return MSG;
}

// Var o = {A: 1, B: "XX", C: {C1: 3, C2: "ww "}};
// Alert (toxml (o ));
VaR o = {
Zi_tid: 'xq9fasfi + 7 wbswdfgsszcw = ',
Zi_isre: 1,
Key: NULL,
Row: 10,
SKIP: 0,
Code: 'ijrgfsfsjqyo4'
};
VaR soap = tosoap ('listinfo', O, 'authorityservicewsdl ');
Alert (SOAP );
</SCRIPT>

 

PS. this script is used to call PHP's WebService (using the standard SOAP protocol). ASPnet's WebService implements both standard soap and common get/post methods, calling is much simpler.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.