src/util/xml-helpers.js
function(doc, nodes, selector, after) {
        var parent = module.exports.resolveParent(doc, selector);
        if (!parent) {
            //Try to create the parent recursively if necessary
            try {
                var parentToCreate = et.XML('<' + path.basename(selector) + '>'),
                    parentSelector = path.dirname(selector);

                this.graftXML(doc, [parentToCreate], parentSelector);
            } catch (e) {
                return false;
            }
            parent = module.exports.resolveParent(doc, selector);
            if (!parent) return false;
        }

        nodes.forEach(function (node) {
            // check if child is unique first
            if (uniqueChild(node, parent)) {
                var children = parent.getchildren();
                var insertIdx = after ? findInsertIdx(children, after) : children.length;

                //TODO: replace with parent.insert after the bug in ElementTree is fixed
                parent.getchildren().splice(insertIdx, 0, node);
            }
        });

        return true;
    }
function(doc, nodes, selector, after) {
        var parent = module.exports.resolveParent(doc, selector);
        if (!parent) {
            //Try to create the parent recursively if necessary
            try {
                var parentToCreate = et.XML('<' + path.basename(selector) + '>'),
                    parentSelector = path.dirname(selector);

                this.graftXML(doc, [parentToCreate], parentSelector);
            } catch (e) {
                return false;
            }
            parent = module.exports.resolveParent(doc, selector);
            if (!parent) return false;
        }

        nodes.forEach(function (node) {
            // check if child is unique first
            if (uniqueChild(node, parent)) {
                var children = parent.getchildren();
                var insertIdx = after ? findInsertIdx(children, after) : children.length;

                //TODO: replace with parent.insert after the bug in ElementTree is fixed
                parent.getchildren().splice(insertIdx, 0, node);
            }
        });

        return true;
    }
function ( doc , nodes , selector , after ) { var parent = module . exports . resolveParent ( doc , selector ) ; if ( ! parent ) { //Try to create the parent recursively if necessary try { var parentToCreate = et . XML ( '<' + path . basename ( selector ) + '>' ) , parentSelector = path . dirname ( selector ) ; this . graftXML ( doc , [ parentToCreate ] , parentSelector ) ; } catch ( e ) { return false ; } parent = module . exports . resolveParent ( doc , selector ) ; if ( ! parent ) return false ; } nodes . forEach ( function ( node ) { // check if child is unique first if ( uniqueChild ( node , parent ) ) { var children = parent . getchildren ( ) ; var insertIdx = after ? findInsertIdx ( children , after ) : children . length ; //TODO: replace with parent.insert after the bug in ElementTree is fixed parent . getchildren ( ) . splice ( insertIdx , 0 , node ) ; } } ) ; return true ; }
adds node to doc at selector, creating parent if it doesn't exist
adds node to doc at selector creating parent if it doesn t exist