OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
687 stars 94 forks source link

Word: xPath parameter in `getNodesAsync` is not working as expected #1263

Closed algomaster99 closed 4 years ago

algomaster99 commented 4 years ago

Expected Behavior

Should have received an array of the nodes corresponding to the xPath.

Current Behavior

An empty array is being showed as the output. empty-array

Steps to Reproduce, or Live Example

Script Lab

Context

I need to store some values in the XML and update them whenever I update things in the document.

Your Environment

algomaster99 commented 4 years ago

I am not able to get the nodes according to the xPath I provide. I always get an empty array. When I pass as xPath, I get he first node and then I have to get nodes from there recursively (by passing ''). Example,

Office.context.document.customXmlParts.getByNamespaceAsync('accordproject.org', (res) => {
      if (res.status === Office.AsyncResultStatus.Succeeded) {
        console.log('xml', res.value);
        res.value[0].getNodesAsync('*/*', (nodes) => {
          if (nodes.status === Office.AsyncResultStatus.Succeeded) {
            console.log('1',nodes.value);
            nodes.value[0].getNodesAsync('*', (res) => {
              if (res.status === Office.AsyncResultStatus.Succeeded) {
                console.log('2', res.value);
                res.value[1].getNodeValueAsync((res) => {
                  if (res.status === Office.AsyncResultStatus.Succeeded) {
                    console.log('3', res.value);
                  }
                })
              }
            });
          }
        })
      }
    });

This is just for demonstration. If xPath doesn't work, I might have to write a recursive function wherein I will get each node one by one.

lindalu-MSFT commented 4 years ago

Hi @algomaster99 I assigned this to one of the Word engs, but I think you might also have luck posting this question to Stack Overflow tagged [office-js] and [Word]. There's a huge developer community there willing to help!

algomaster99 commented 4 years ago

@lindalu-MSFT I have asked the question here https://stackoverflow.com/questions/62809742/xpath-parameter-in-getnodesasync-is-not-working-as-expected.

weshi commented 4 years ago

The answer is provided from the above stackoverflow question. Closing this one.