質問

XML要素を指すXpathnavigatorオブジェクトがあります。要素の名前を別の名前に変更したい(また、関連するエンド要素の名前も変更します)。これはxpathnavigatorを使用して実行できますか?

(ワークアラウンドがあります。これは、要素を削除して別の名前で再挿入することですが、非常に大きなドキュメントを処理しているため、パフォーマンスの問題を引き起こす可能性があります)

役に立ちましたか?

解決

基礎となるXMLドキュメントの表現が何であるかに依存します。 Xdocumentを使用している場合は、次のことができます。

(XElement)(navigator.UnderlyingObject).Name = ...

Xmldocument(提案されている場合を除く)、またはXpathDocumentでは不可能だと思います。

他のヒント

この質問に興味がある他の人、そして質問を正しく理解していて、要素ノードの名前を変更したい場合は、Xpathnavigatorから自分自身を使用して非常に簡単に実行可能であることがわかります。 .NET Frameworkバージョン4.0を使用していますが、これはしばらく前から存在しているようです。

(クイックC#の例)

    XmlDocument reportServerDocument = new XmlDocument();
    reportServerDocument.Load("C:\Path\to\ReportServer\rsreportserver.config");

    XPathNavigator reportServerDocumentNavigator = 
        reportServerDocument.CreateNavigator();

    XPathNavigator authenticationTypesNode = 
        reportServerDocumentNavigator.SelectSingleNode(
            "//Authentication/AuthenticationTypes/RSWindowsNegotiate");

    authenticationTypesNode.ReplaceSelf("<Custom/>");

    reportServerDocument.Save("C:\Path\to\ReportServer\rsreportserver.config");
    log.Info("Updated the AuthenticationTypes: " + 
       authenticationTypesNode.OuterXml);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top