lib/commands/source.js
function getTreeForXML (srcTree) {
  function getTree (element, elementIndex, parentPath) {
    let curPath = `${parentPath}/${elementIndex}`;
    let rect = element.rect || {};
    let subtree = {
      '@': {
        type: `XCUIElementType${element.type}`,
        enabled: parseInt(element.isEnabled, 10) === 1,
        visible: parseInt(element.isVisible, 10) === 1,
        x: rect.x,
        y: rect.y,
        width: rect.width,
        height: rect.height,
      },
      '>': []
    };
    if (element.name !== null) {
      subtree['@'].name = element.name;
    }
    if (element.label !== null) {
      subtree['@'].label = element.label;
    }
    if (element.value !== null) {
      subtree['@'].value = element.value;
    }
    for (let i = 0; i < (element.children || []).length; i++) {
      subtree['>'].push(getTree(element.children[i], i, curPath));
    }
    return {
      [`XCUIElementType${element.type}`]: subtree
    };
  }
  let tree = getTree(srcTree, 0, '');
  return tree;
}
function getTreeForXML (srcTree) {
  function getTree (element, elementIndex, parentPath) {
    let curPath = `${parentPath}/${elementIndex}`;
    let rect = element.rect || {};
    let subtree = {
      '@': {
        type: `XCUIElementType${element.type}`,
        enabled: parseInt(element.isEnabled, 10) === 1,
        visible: parseInt(element.isVisible, 10) === 1,
        x: rect.x,
        y: rect.y,
        width: rect.width,
        height: rect.height,
      },
      '>': []
    };
    if (element.name !== null) {
      subtree['@'].name = element.name;
    }
    if (element.label !== null) {
      subtree['@'].label = element.label;
    }
    if (element.value !== null) {
      subtree['@'].value = element.value;
    }
    for (let i = 0; i < (element.children || []).length; i++) {
      subtree['>'].push(getTree(element.children[i], i, curPath));
    }
    return {
      [`XCUIElementType${element.type}`]: subtree
    };
  }
  let tree = getTree(srcTree, 0, '');
  return tree;
}
/* Will get JSON of the form:
{ isEnabled: '1',
isVisible: '1',
frame: '{{0, 0}, {375, 667}}',
children:
[ { isEnabled: '1',
isVisible: '1',
frame: '{{0, 0}, {375, 667}}',
children: [],
rect: { x: 0, y: 0, width: 375, height: 667 },
value: null,
label: null,
type: 'Other',
name: null,
rawIdentifier: null },
rect: { origin: { x: 0, y: 0 }, size: { width: 375, height: 667 } },
value: null,
label: 'UICatalog',
type: 'Application',
name: 'UICatalog',
rawIdentifier: null }