1

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

(回避策があります。要素を削除して別の名前で再挿入しますが、非常に大きなドキュメントを処理しているため、パフォーマンスの問題が発生する可能性があります)

4

2 に答える 2

1

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

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

XmlDocument(あなたが提案する場合を除いて)またはXPathDocumentではそれが可能ではないと思います。

于 2010-09-30T15:33:45.590 に答える
1

この質問に興味があり、質問を正しく理解していて、要素ノードの名前を変更したい場合は、ReplaceSelfを使用して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);
于 2013-04-25T01:05:57.160 に答える