var obj = { title: 'I need another test outline',
  description: '<p>United States</p>\n\t\t\t\t<ul>\n\t\t\t\t\t<li>Far West</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Alaska</li>\n\t\t\t\t\t\t<li>California</li>\n\t\t\t\t\t\t<li>Hawaii</li>\n\t\t\t\t\t\t<li>Nevada</li>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t<li>Reno</li>\n\t\t\t\t\t\t\t<li>Las Vegas</li>\n\t\t\t\t\t\t\t<li>Ely</li>\n\t\t\t\t\t\t\t<li>Gerlach</li>\n\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t<li>Oregon</li>\n\t\t\t\t\t\t<li>Washington</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Great Plains</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Kansas</li>\n\t\t\t\t\t\t<li>Nebraska</li>\n\t\t\t\t\t\t<li>North Dakota</li>\n\t\t\t\t\t\t<li>Oklahoma</li>\n\t\t\t\t\t\t<li>South Dakota</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Mid-Atlantic</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Delaware</li>\n\t\t\t\t\t\t<li>Maryland</li>\n\t\t\t\t\t\t<li>New Jersey</li>\n\t\t\t\t\t\t<li>New York</li>\n\t\t\t\t\t\t<li>Pennsylvania</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Midwest</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Illinois</li>\n\t\t\t\t\t\t<li>Indiana</li>\n\t\t\t\t\t\t<li>Iowa</li>\n\t\t\t\t\t\t<li>Kentucky</li>\n\t\t\t\t\t\t<li>Michigan</li>\n\t\t\t\t\t\t<li>Minnesota</li>\n\t\t\t\t\t\t<li>Missouri</li>\n\t\t\t\t\t\t<li>Ohio</li>\n\t\t\t\t\t\t<li>West Virginia</li>\n\t\t\t\t\t\t<li>Wisconsin</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Mountains</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Colorado</li>\n\t\t\t\t\t\t<li>Idaho</li>\n\t\t\t\t\t\t<li>Montana</li>\n\t\t\t\t\t\t<li>Utah</li>\n\t\t\t\t\t\t<li>Wyoming</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>New England</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Connecticut</li>\n\t\t\t\t\t\t<li>Maine</li>\n\t\t\t\t\t\t<li>Massachusetts</li>\n\t\t\t\t\t\t<li>New Hampshire</li>\n\t\t\t\t\t\t<li>Rhode Island</li>\n\t\t\t\t\t\t<li>Vermont</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>South</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Alabama</li>\n\t\t\t\t\t\t<li>Arkansas</li>\n\t\t\t\t\t\t<li>Florida</li>\n\t\t\t\t\t\t<li>Georgia</li>\n\t\t\t\t\t\t<li>Louisiana</li>\n\t\t\t\t\t\t<li>Mississippi</li>\n\t\t\t\t\t\t<li>North Carolina</li>\n\t\t\t\t\t\t<li>South Carolina</li>\n\t\t\t\t\t\t<li>Tennessee</li>\n\t\t\t\t\t\t<li>Virginia</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Southwest</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Arizona</li>\n\t\t\t\t\t\t<li>New Mexico</li>\n\t\t\t\t\t\t<li>Texas</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</ul>',
  summary: '<p>United States</p>\n\t\t\t\t<ul>\n\t\t\t\t\t<li>Far West</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Alaska</li>\n\t\t\t\t\t\t<li>California</li>\n\t\t\t\t\t\t<li>Hawaii</li>\n\t\t\t\t\t\t<li>Nevada</li>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t<li>Reno</li>\n\t\t\t\t\t\t\t<li>Las Vegas</li>\n\t\t\t\t\t\t\t<li>Ely</li>\n\t\t\t\t\t\t\t<li>Gerlach</li>\n\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t<li>Oregon</li>\n\t\t\t\t\t\t<li>Washington</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Great Plains</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Kansas</li>\n\t\t\t\t\t\t<li>Nebraska</li>\n\t\t\t\t\t\t<li>North Dakota</li>\n\t\t\t\t\t\t<li>Oklahoma</li>\n\t\t\t\t\t\t<li>South Dakota</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Mid-Atlantic</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Delaware</li>\n\t\t\t\t\t\t<li>Maryland</li>\n\t\t\t\t\t\t<li>New Jersey</li>\n\t\t\t\t\t\t<li>New York</li>\n\t\t\t\t\t\t<li>Pennsylvania</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Midwest</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Illinois</li>\n\t\t\t\t\t\t<li>Indiana</li>\n\t\t\t\t\t\t<li>Iowa</li>\n\t\t\t\t\t\t<li>Kentucky</li>\n\t\t\t\t\t\t<li>Michigan</li>\n\t\t\t\t\t\t<li>Minnesota</li>\n\t\t\t\t\t\t<li>Missouri</li>\n\t\t\t\t\t\t<li>Ohio</li>\n\t\t\t\t\t\t<li>West Virginia</li>\n\t\t\t\t\t\t<li>Wisconsin</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Mountains</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Colorado</li>\n\t\t\t\t\t\t<li>Idaho</li>\n\t\t\t\t\t\t<li>Montana</li>\n\t\t\t\t\t\t<li>Utah</li>\n\t\t\t\t\t\t<li>Wyoming</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>New England</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Connecticut</li>\n\t\t\t\t\t\t<li>Maine</li>\n\t\t\t\t\t\t<li>Massachusetts</li>\n\t\t\t\t\t\t<li>New Hampshire</li>\n\t\t\t\t\t\t<li>Rhode Island</li>\n\t\t\t\t\t\t<li>Vermont</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>South</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Alabama</li>\n\t\t\t\t\t\t<li>Arkansas</li>\n\t\t\t\t\t\t<li>Florida</li>\n\t\t\t\t\t\t<li>Georgia</li>\n\t\t\t\t\t\t<li>Louisiana</li>\n\t\t\t\t\t\t<li>Mississippi</li>\n\t\t\t\t\t\t<li>North Carolina</li>\n\t\t\t\t\t\t<li>South Carolina</li>\n\t\t\t\t\t\t<li>Tennessee</li>\n\t\t\t\t\t\t<li>Virginia</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Southwest</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Arizona</li>\n\t\t\t\t\t\t<li>New Mexico</li>\n\t\t\t\t\t\t<li>Texas</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</ul>',
  date: new Date('Thu Oct 16 2014 13:25:11 GMT-0400 (EDT)'),
  pubdate: new Date('Thu Oct 16 2014 13:25:11 GMT-0400 (EDT)'),
  pubDate: new Date('Thu Oct 16 2014 13:25:11 GMT-0400 (EDT)'),
  link: 'http://scripting.com/2014/10/16/#a1413480311',
  guid: 'http://scripting.com/2014/10/16/#a1413480311',
  author: 'dave.winer@gmail.com',
  comments: null,
  origlink: null,
  image: {},
  source: {},
  categories: [],
  enclosures: [],
  'rss:@': {},
  'rss:title': { '@': {}, '#': 'I need another test outline' },
  'rss:link': { '@': {}, '#': 'http://scripting.com/2014/10/16/#a1413480311' },
  'rss:description':
   { '@': {},
     '#': '<p>United States</p>\n\t\t\t\t<ul>\n\t\t\t\t\t<li>Far West</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Alaska</li>\n\t\t\t\t\t\t<li>California</li>\n\t\t\t\t\t\t<li>Hawaii</li>\n\t\t\t\t\t\t<li>Nevada</li>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t<li>Reno</li>\n\t\t\t\t\t\t\t<li>Las Vegas</li>\n\t\t\t\t\t\t\t<li>Ely</li>\n\t\t\t\t\t\t\t<li>Gerlach</li>\n\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t<li>Oregon</li>\n\t\t\t\t\t\t<li>Washington</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Great Plains</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Kansas</li>\n\t\t\t\t\t\t<li>Nebraska</li>\n\t\t\t\t\t\t<li>North Dakota</li>\n\t\t\t\t\t\t<li>Oklahoma</li>\n\t\t\t\t\t\t<li>South Dakota</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Mid-Atlantic</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Delaware</li>\n\t\t\t\t\t\t<li>Maryland</li>\n\t\t\t\t\t\t<li>New Jersey</li>\n\t\t\t\t\t\t<li>New York</li>\n\t\t\t\t\t\t<li>Pennsylvania</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Midwest</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Illinois</li>\n\t\t\t\t\t\t<li>Indiana</li>\n\t\t\t\t\t\t<li>Iowa</li>\n\t\t\t\t\t\t<li>Kentucky</li>\n\t\t\t\t\t\t<li>Michigan</li>\n\t\t\t\t\t\t<li>Minnesota</li>\n\t\t\t\t\t\t<li>Missouri</li>\n\t\t\t\t\t\t<li>Ohio</li>\n\t\t\t\t\t\t<li>West Virginia</li>\n\t\t\t\t\t\t<li>Wisconsin</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Mountains</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Colorado</li>\n\t\t\t\t\t\t<li>Idaho</li>\n\t\t\t\t\t\t<li>Montana</li>\n\t\t\t\t\t\t<li>Utah</li>\n\t\t\t\t\t\t<li>Wyoming</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>New England</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Connecticut</li>\n\t\t\t\t\t\t<li>Maine</li>\n\t\t\t\t\t\t<li>Massachusetts</li>\n\t\t\t\t\t\t<li>New Hampshire</li>\n\t\t\t\t\t\t<li>Rhode Island</li>\n\t\t\t\t\t\t<li>Vermont</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>South</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Alabama</li>\n\t\t\t\t\t\t<li>Arkansas</li>\n\t\t\t\t\t\t<li>Florida</li>\n\t\t\t\t\t\t<li>Georgia</li>\n\t\t\t\t\t\t<li>Louisiana</li>\n\t\t\t\t\t\t<li>Mississippi</li>\n\t\t\t\t\t\t<li>North Carolina</li>\n\t\t\t\t\t\t<li>South Carolina</li>\n\t\t\t\t\t\t<li>Tennessee</li>\n\t\t\t\t\t\t<li>Virginia</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t<li>Southwest</li>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>Arizona</li>\n\t\t\t\t\t\t<li>New Mexico</li>\n\t\t\t\t\t\t<li>Texas</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</ul>' },
  'source:outline':
   { '@':
      { text: 'I need another test outline',
        created: 'Thu, 16 Oct 2014 17:25:11 GMT',
        type: 'idea',
        name: 'iNeedAnotherTestOutline' },
     'source:outline':
      { '@': { text: 'United States' },
        'source:outline':
         [ { '@': { text: 'Far West' },
             'source:outline':
              [ { '@': { text: 'Alaska' } },
                { '@': { text: 'California' } },
                { '@': { text: 'Hawaii' } },
                { '@': { text: 'Nevada' },
                  'source:outline':
                   [ { '@': { text: 'Reno', created: 'Tue, 12 Jul 2005 23:56:35 GMT' } },
                     { '@': { text: 'Las Vegas', created: 'Tue, 12 Jul 2005 23:56:37 GMT' } },
                     { '@': { text: 'Ely', created: 'Tue, 12 Jul 2005 23:56:39 GMT' } },
                     { '@': { text: 'Gerlach', created: 'Tue, 12 Jul 2005 23:56:47 GMT' } } ] },
                { '@': { text: 'Oregon' } },
                { '@': { text: 'Washington' } } ] },
           { '@': { text: 'Great Plains' },
             'source:outline':
              [ { '@': { text: 'Kansas' } },
                { '@': { text: 'Nebraska' } },
                { '@': { text: 'North Dakota' } },
                { '@': { text: 'Oklahoma' } },
                { '@': { text: 'South Dakota' } } ] },
           { '@': { text: 'Mid-Atlantic' },
             'source:outline':
              [ { '@': { text: 'Delaware' } },
                { '@': { text: 'Maryland' } },
                { '@': { text: 'New Jersey' } },
                { '@': { text: 'New York' } },
                { '@': { text: 'Pennsylvania' } } ] },
           { '@': { text: 'Midwest' },
             'source:outline':
              [ { '@': { text: 'Illinois' } },
                { '@': { text: 'Indiana' } },
                { '@': { text: 'Iowa' } },
                { '@': { text: 'Kentucky' } },
                { '@': { text: 'Michigan' } },
                { '@': { text: 'Minnesota' } },
                { '@': { text: 'Missouri' } },
                { '@': { text: 'Ohio' } },
                { '@': { text: 'West Virginia' } },
                { '@': { text: 'Wisconsin' } } ] },
           { '@': { text: 'Mountains' },
             'source:outline':
              [ { '@': { text: 'Colorado' } },
                { '@': { text: 'Idaho' } },
                { '@': { text: 'Montana' } },
                { '@': { text: 'Utah' } },
                { '@': { text: 'Wyoming' } } ] },
           { '@': { text: 'New England' },
             'source:outline':
              [ { '@': { text: 'Connecticut' } },
                { '@': { text: 'Maine' } },
                { '@': { text: 'Massachusetts' } },
                { '@': { text: 'New Hampshire' } },
                { '@': { text: 'Rhode Island' } },
                { '@': { text: 'Vermont' } } ] },
           { '@': { text: 'South' },
             'source:outline':
              [ { '@': { text: 'Alabama' } },
                { '@': { text: 'Arkansas' } },
                { '@': { text: 'Florida' } },
                { '@': { text: 'Georgia' } },
                { '@': { text: 'Louisiana' } },
                { '@': { text: 'Mississippi' } },
                { '@': { text: 'North Carolina' } },
                { '@': { text: 'South Carolina' } },
                { '@': { text: 'Tennessee' } },
                { '@': { text: 'Virginia' } } ] },
           { '@': { text: 'Southwest' },
             'source:outline':
              [ { '@': { text: 'Arizona' } },
                { '@': { text: 'New Mexico' } },
                { '@': { text: 'Texas' } } ] } ] } },
  'rss:pubdate': { '@': {}, '#': 'Thu, 16 Oct 2014 17:25:11 GMT' },
  permalink: 'http://scripting.com/2014/10/16/#a1413480311',
  'rss:guid': { '@': {}, '#': 'http://scripting.com/2014/10/16/#a1413480311' },
  meta:
   { '#ns': [ { 'xmlns:source': 'http://source.smallpict.com/2014/07/12/theSourceNamespace.html' } ],
     '@': [ { 'xmlns:source': 'http://source.smallpict.com/2014/07/12/theSourceNamespace.html' } ],
     '#xml': { version: '1.0' },
     '#type': 'rss',
     '#version': '2.0',
     title: 'Scripting News',
     description: 'Dave Winer\'s weblog, started in April 1997, bootstrapped the blogging revolution.',
     date: new Date('Thu Oct 16 2014 19:27:07 GMT-0400 (EDT)'),
     pubdate: new Date('Thu Oct 16 2014 19:27:07 GMT-0400 (EDT)'),
     pubDate: new Date('Thu Oct 16 2014 19:27:07 GMT-0400 (EDT)'),
     link: 'http://scripting.com/',
     xmlurl: null,
     xmlUrl: null,
     author: 'dave.winer@gmail.com',
     language: 'en-us',
     favicon: null,
     copyright: null,
     generator: 'Fargo v1.68',
     cloud: {},
     image: {},
     categories: [],
     'rss:@': {},
     'rss:title': { '@': {}, '#': 'Scripting News' },
     'rss:link': { '@': {}, '#': 'http://scripting.com/' },
     'rss:description':
      { '@': {},
        '#': 'Dave Winer\'s weblog, started in April 1997, bootstrapped the blogging revolution.' },
     'rss:pubdate': { '@': {}, '#': 'Thu, 16 Oct 2014 23:27:07 GMT' },
     'rss:lastbuilddate': { '@': {}, '#': 'Thu, 16 Oct 2014 23:27:07 GMT' },
     'rss:language': { '@': {}, '#': 'en-us' },
     'rss:generator': { '@': {}, '#': 'Fargo v1.68' },
     'rss:docs': { '@': {}, '#': 'http://cyber.law.harvard.edu/rss/rss.html' },
     'rss:webmaster':
      { '@': {},
        '#': 'dave.winer@gmail.com',
        name: '',
        email: 'dave.winer@gmail.com' },
     'source:account':
      [ { '@': { service: 'twitter' }, '#': 'davewiner' },
        { '@': { service: 'facebook' }, '#': 'dave.winer.12' } ] } };

function convertOutline(jstruct) { //7/16/14 by DW
    var theNewOutline = {},
        atts, subs;
    if (jstruct["source:outline"] != undefined) {
        if (jstruct["@"] != undefined) {
            atts = jstruct["@"];
            subs = jstruct["source:outline"];
        } else {
            atts = jstruct["source:outline"]["@"];
            subs = jstruct["source:outline"]["source:outline"];
        }
    } else {
        atts = jstruct["@"];
        subs = undefined;
    }
    for (var x in atts) {
        theNewOutline[x] = atts[x];
    }
    if (subs != undefined) {
        theNewOutline.subs = [];
        if (subs instanceof Array) {
            for (var i = 0; i < subs.length; i++) {
                theNewOutline.subs[i] = convertOutline(subs[i]);
            }
        } else {
            theNewOutline.subs = [];
            theNewOutline.subs[0] = {};
            for (var x in subs["@"]) {
                theNewOutline.subs[0][x] = subs["@"][x];
            }
            theNewOutline.subs[0] = subs;
        }
    }
    return (theNewOutline);
}

function copyScalars (source, dest) { //8/31/14 by DW
  for (var x in source) { 
    var type, val = source [x];
    if (val instanceof Date) { 
      val = val.toString ();
    }
    type = typeof (val);
    if ((type != "object") && (type != undefined)) {
      dest [x] = val;
    }
  }
}

function newConvertOutline(jstruct) {
    var theNewOutline = {};
    if (jstruct["@"] != undefined) {
        copyScalars(jstruct["@"], theNewOutline);
    }
    if (jstruct["source:outline"] != undefined) {
        if (jstruct["source:outline"] instanceof Array) {
            var theArray = jstruct["source:outline"];
            theNewOutline.subs = [];
            for (var i = 0; i < theArray.length; i++) {
                theNewOutline.subs[theNewOutline.subs.length] = newConvertOutline(theArray[i]);
            }
        } else {
            theNewOutline.subs = [
                newConvertOutline(jstruct["source:outline"])
            ];
        }
    }
    return (theNewOutline);
}

console.log(require('util').inspect(convertOutline(obj), null, 10));
console.log(require('util').inspect(newConvertOutline(obj), null, 10));

