単語vsto addinが、CustomXMLNode.SelectSingleNodeを呼び出す際に例外なく失敗します。Word VSTO CustomXMLNode.SelectSingleNodeがOfficeのアップグレード後に失敗する
アドインは2007 - 2013という単語でうまく動作しますが、バージョン2016では宣言されていない名前空間接頭辞 'ns0'への参照で失敗します。
私は、XPathと、これらのメソッドを使用せずにXMLをナビゲート回避策を作ったが、まだこの問題を解決する方法を理解する必要がありました。
var xPathExpression = String.Format(
"{0}:{1}[1]",
customXml.NamespaceManager.LookupPrefix(xmlRef.DefaultNamespace),
xmlRef.ElementNames.DisplayText.LocalName);
groupMembers[j].SelectSingleNode(xPathExpression);
結果xPathExpressionが
ns0:DisplayText[1]
であるXMLは次のようになります。
通常<MyXmlTest xmlns="http://www.myxmltest.com/document">
<Ribbon visible="true">
<Group name="xmlProperties">Document Properties</Group>
<Group name="xmlActions">Other Properties</Group>
</Ribbon>
<DocumentList>
<Document>
<Properties ribbonLabel="Hello World Menu">
<Property name="helloWorld">
<RibbonButton groupName="xmlActions">
<DisplayText>Hello World</DisplayText>
<PlaceholderText>N/A</PlaceholderText>
<Tooltip>Some text goes here.</Tooltip>
</RibbonButton>
<Content/>
</Property>
<Property name="title">
<RibbonButton groupName="xmlProperties">
<DisplayText>Hello World Text</DisplayText>
<PlaceholderText>N/A</PlaceholderText>
<Tooltip>Insert Hello World in Document</Tooltip>
</RibbonButton>
<Content>Testing</Content>
</Property>
</Properties>
</Document>
</DocumentList>
</MyXmlTest>
、多分あなたは 'ローカル名を使用して名前空間を無視しようとすることができます()' : '* [local-name()= 'DisplayText'] [1]' – har07
それは動作します!私は、ドキュメント内の最初のノードを選択したものと同じようなものを試しました。現在のノードの最初のノードではなく、おそらく同じ構文です。ありがとうございました。答えを追加した場合、私はそれを – Kman
としてマークします。あなたはたぶん以前に '{* * [local-name()= 'DisplayText'] [1]'を試していました。 '/'でXPathを起動すると、ドキュメントルートから検索されます。 – har07