Example #1
0
	var parse = function(o) {
		if (getype(o) != 'object') return;
		for(var key in o) {
			if (o.hasOwnProperty(key) && o[key] != null){
				var type1 = getype(o[key]);
				if (type1 == 'object') {
					xw.startElement(getname(key));
					parse(o[key]);
					xw.endElement();
				}
				else if (type1 == 'array' && o[key].length <= 0) {
					xw.startElement(getname(key)).endElement();
				}
				else if (type1 == 'array' && o[key].length > 0) {
					var type2 = getype(o[key][0]);
					if (type2 == 'object') {
						o[key].forEach(function(item, index) {
								if (key == '$element' || key == '$e' || key == '#element' || key == '_element' || key == '_e') {
									parse(item);
								}
								else {
									xw.startElement(getname(key));
									parse(item);
									xw.endElement();
								}
						});
					}
					else {
						o[key].forEach(function(item, index) {
								if (key == '$element' || key == '$e' || key == '#element' || key == '_element' || key == '_e') {
									xw.startCData().text(getval(item)).endCData();
								}
								else {
									xw.startElement(getname(key));
									xw.startCData().text(getval(item)).endCData();
									xw.endElement();
								}
						});
					}
				}
				else {
					if (key == '$text' || key == '$t' || key == '#text' || key == '_text' || key == '_t') {
						xw.text(getval(o[key]));
					}
					else if (key == '$comment' || key == '$c' || key == '#comment' || key == '_comment' || key == '_c') {
						xw.startComment().text(getval(o[key])).endComment();
					}
					else if (key == '$cdata' || key == '$cd' || key == '#cdata' || key == '_cdata' || key == '_cd') {
						xw.startCData().text(getval(o[key])).endCData();
					}
					else  {
						xw.startAttribute(getname(key)).text(getval(o[key])).endAttribute();
					}
				}
			}
		}
	}
Example #2
0
 var parse = function (o) {
   if (getype(o) != 'object') {
     return;
   }
   var keys = sortKeys(o);
   for (var index in keys) {
     var key = keys[index];
     var val = o[key];
     var type1 = getype(val);
     if (type1 == 'object') {
       xw.startElement(getname(key));
       parse(val);
       xw.endElement();
     }
     else if (type1 == 'array' && val.length <= 0) {
       xw.startElement(getname(key)).endElement();
     }
     else if (type1 == 'array' && val.length > 0) {
       var type2 = getype(val[0]);
       if (type2 == 'object') {
         val.forEach(function (item, index) {
             if (key == '$element' || key == '$e' || key == '#element') {
               parse(item);
             }
             else {
               xw.startElement(getname(key));
               parse(item);
               xw.endElement();
             }
           }
         );
       }
       else {
         val.forEach(function (item, index) {
             if (key == '$element' || key == '$e' || key == '#element') {
               xw.startCData().text(getval(item)).endCData();
             }
             else {
               xw.startElement(getname(key));
               xw.startCData().text(getval(item)).endCData();
               xw.endElement();
             }
           }
         );
       }
     }
     else {
       if (key == '$text' || key == '$t' || key == '#text') {
         xw.text(getval(val));
       }
       else if (key == '$comment' || key == '$c' || key == '#comment') {
         xw.startComment().text(getval(val)).endComment();
       }
       else if (key == '$cdata' || key == '$cd' || key == '#cdata' || key == '#cd') {
         xw.startCData().text(getval(val)).endCData();
       }
       else  {
         xw.startAttribute(getname(key)).text(getval(val)).endAttribute();
       }
     }
   }
 }
Example #3
0
 var parse = function (o) {
   if (getype(o) != 'object') {
     return;
   }
   var keys = sortKeys(o);
   var ELT = options.specialChar + elementLongTag;
   var EST = options.specialChar + elementShortTag;
   for (var index in keys) {
     var key = keys[index];
     var val = o[key];
     var type1 = getype(val);
     if (type1 == 'object') {
       xw.startElement(getname(key));
       parse(val);
       xw.endElement();
     }
     else if (type1 == 'array' && val.length <= 0) {
       xw.startElement(getname(key)).endElement();
     }
     else if (type1 == 'array' && val.length > 0) {
       var type2 = getype(val[0]);
       if (type2 == 'object') {
         val.forEach(function (item, index) {
             if (key === ELT || key === EST || key == '#element') {
               parse(item);
             }
             else {
               xw.startElement(getname(key));
               parse(item);
               xw.endElement();
             }
           }
         );
       }
       else {
         val.forEach(function (item, index) {
             if (key == ELT || key == EST || key == '#element') {
               xw.startCData().text(getval(item)).endCData();
             }
             else {
               xw.startElement(getname(key));
               xw.startCData().text(getval(item)).endCData();
               xw.endElement();
             }
           }
         );
       }
     }
     else {
       var TLT = options.specialChar + textLongTag;
       var TST = options.specialChar + textShortTag;
       if (key === TLT || key === TST || key == '#text') {
         xw.text(getval(val));
       }
       else if (key === options.specialChar + commentLongTag || key === options.specialChar + commentShortTag || key == '#comment') {
         xw.startComment().text(getval(val)).endComment();
       }
       else if (key === options.specialChar + cdataLongTag || key === options.specialChar + cdataShortTag || key == '#cdata' || key == '#cd') {
         xw.startCData().text(getval(val)).endCData();
       }
       else  {
         xw.startAttribute(getname(key)).text(getval(val)).endAttribute();
       }
     }
   }
 }