getNodesAsync
has a parameter called xPath
which I think should help me to query my custom XML. I think it is malfunctioning because it only returns the node when I pass an *
. Any other path (even if it exists), returns an empty array.
Run
to add the xml<AP xmlns="accordproject.org">
<template xmlns="acceptance-of-delivery">
<shipper>Aman Sharma</shipper>
</template>
</AP>
Get node
is supposed to fetch the nodes at /AP/template
.Delete XML
will delete the customXML.Link to ScriptLab snippet: https://gist.github.com/algomaster99/fc10bc8fcf3429f1d3ad1fbadaa3216f
I think I've found how this works. It seems that for the custom XML parts that are created with the Common Office JavaScript APIs (as distinct from Custom XML Parts created in the Word-specific JavaScript APIs), Office assigns default aliases for the namespaces in order: ns0
, ns1
, etc. You have to use these in the xpath variables. So in your gist, if you change the first parameter of the call to getNodesAsync
to "/ns0:AP/ns1:template"
it works.