2017-03-21 7 views
0

SelectNodeは、値を持っていても常に0カウントを返します。ノードリストを読み込むためのSelectNodes常に0カウントを返します。

<?xml version="1.0" encoding="utf-16"?> 
    <Configurations xmlns="DEH_Common.Schemas"> 
     <sftpConfiguration> 
     <file> 
      <filedetails> 
      <fileext>csv</fileext> 
      <DataContentDetailId>1</DataContentDetailId> 
      </filedetails> 
    </file> 
    </sftpConfiguration> 
    </Configurations> 

C#のあなたのXPathはsftpConfiguration/file

XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("sftpConfiguration/file"); 

答えて

1

それはあなたのxmlで名前空間を使用しての、あなたがxmlDoc and also no need to use DocumentElement`に名前空間を追加する必要がありますので、このコードは仕事になります。

var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); 
nsmgr.AddNamespace("a", "DEH_Common.Schemas"); 
XmlNodeList nodeList = xmlDoc.SelectNodes("//a:sftpConfiguration/a:file", nsmgr); 
+0

これは試しましたか?それは動作しましたか? –

+0

それは働いた。ありがとうございました。 –

1

DocumentElementは、構成ノードである:

xmlDoc.DocumentElement.SelectNodes("/Configurations[@*]/sftpConfiguration/file"); 
+0

私はすでにこれを試みたが、まだ0のカウントを取得しています。 –

+0

はクイックサンプルを作成し、 'nodeList.Count'は' 1'を返します。 xmlns属性を削除して、エンコーディングをutf-8に変更しなければなりませんでした – bradbury9

0

これを試してみてくださいする必要がありますので....あなたのXMLで

XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("//Configurations/sftpConfiguration/file"); 
+0

私はこれを試しましたが、まだカウント0になりました。 –

+0

私はそれを得ました。これはネームスペースに関連しています –

関連する問題