none
adding Nodes in customXML RRS feed

  • Question

  • Hello there,

    I am trying to use CustomXmlNode.setXmlAsync() to add a Node to an existing customXML File. Unfortunatelly this does not seem to work since I always get the error: result.status = “failed” result.error.code = 6100. Under which conditions does this method work? My Xml should be valid, since I have successfully added it as a new file with addAsync().

    I am trying this code:

        Office.context.document.customXmlParts.getByNamespaceAsync("http://schemas.openxmlformats.org/officeDocument/2006/bibliography", function (eventArgs) {
            var xmlParts = eventArgs.value;
    
            if (xmlParts && xmlParts.length > 0) {
                // Try to append xml to first xmlPart
                xmlParts[0].getNodesAsync('*/*', function (nodeResults) {
                    if (nodeResults.value && nodeResults.value.length > 0) {
                        var lastSourceNode = nodeResults.value[nodeResults.value.length - 1];
                        lastSourceNode.getXmlAsync(function (xmlResult) {
                            lastSourceNode.setXmlAsync(xmlResult.value + bookXml, function (addResult) {
                                if (addResult.status == "succeeded") {
                                    callback(true);
                                } else callback(false);
                            });
                        });
                    }
                });
            } 
        });

    The only other option coming to my mind would be to get all XML from customXMLParts from same namespace, accumulate them, add my additional XML then deleting all customXMLParts and adding one new Part with all formerly xml plus mine.

    I am pretty frustrated at the moment since I cannot get this to work but documentation hints it should...

    I would greatly appreciate any advice you might have on the matter.

    Friday, June 21, 2013 11:04 AM