aboutsummaryrefslogtreecommitdiffstats
path: root/release/build/js/xml.js
blob: 1d50558e1c5c8dadbd107711eed00ea2db4f7dd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Object.toXML = function( obj, tag ) {
  if ( obj.constructor == Array ) {
    var ret = "";
    for ( var i = 0; i < obj.length; i++ )
      ret += Object.toXML( obj[i], tag );
    return ret;
  } else if ( obj.constructor == Object ) {
    var tag = tag || "tmp";
    var p = "", child = "";

    for ( var i in obj )
      if ( ( obj[i].constructor != String && obj[i].constructor != Number ) || /</.test(obj[i] + "") || Object.toXML.force[i] )
        child += Object.toXML( obj[i], i );
      else
        p += " " + i + "='" + (obj[i] + "").replace(/'/g, "&apos;") + "'";

    return "<" + tag + p + ( child ?  ">\n" + child + "</" + tag + ">\n" : "/>\n" );
  } else if ( obj.constructor == String || obj.constructor == Number ) {
    return "<" + tag + ">" + obj + "</" + tag + ">\n";
  }

  return "";
};

Object.toXML.force = {};