org.symbian.tools.wrttools.previewer/preview/script/xml2json.js
changeset 210 0f7abfd6ae62
parent 37 641b65b14318
child 273 b1f63c2c240c
equal deleted inserted replaced
209:7f0d53ed35c6 210:0f7abfd6ae62
       
     1 /**
       
     2  * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Symbian Foundation - initial contribution.
       
    11  * Contributors:
       
    12  */
       
    13 
     1 /*
    14 /*
     2 xml2json v 1.1
    15 xml2json v 1.1
     3 copyright 2005-2007 Thomas Frank
    16 copyright 2005-2007 Thomas Frank
     4 
    17 
     5 This program is free software under the terms of the 
    18 This program is free software under the terms of the 
    26 		var y=this.xml_to_object(x).jsontagwrapper;
    39 		var y=this.xml_to_object(x).jsontagwrapper;
    27 		if(debug){y=this.show_json_structure(y,debug)};
    40 		if(debug){y=this.show_json_structure(y,debug)};
    28 		return y
    41 		return y
    29 	},
    42 	},
    30 	xml_to_object:function(xmlcode){
    43 	xml_to_object:function(xmlcode){
    31 		var x=xmlcode.replace(/<\//g,"§");
    44 		var x=xmlcode.replace(/<\//g,"�");
    32 		x=x.split("<");
    45 		x=x.split("<");
    33 		var y=[];
    46 		var y=[];
    34 		var level=0;
    47 		var level=0;
    35 		var opentags=[];
    48 		var opentags=[];
    36 		for (var i=1;i<x.length;i++){
    49 		for (var i=1;i<x.length;i++){
    37 			var tagname=x[i].split(">")[0];
    50 			var tagname=x[i].split(">")[0];
    38 			opentags.push(tagname);
    51 			opentags.push(tagname);
    39 			level++
    52 			level++
    40 			y.push(level+"<"+x[i].split("§")[0]);
    53 			y.push(level+"<"+x[i].split("�")[0]);
    41 			while(x[i].indexOf("§"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()}
    54 			while(x[i].indexOf("�"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()}
    42 		};
    55 		};
    43 		var oldniva=-1;
    56 		var oldniva=-1;
    44 		var objname="this.xmlobject";
    57 		var objname="this.xmlobject";
    45 		for (var i=0;i<y.length;i++){
    58 		for (var i=0;i<y.length;i++){
    46 			var preeval="";
    59 			var preeval="";