我有以下xml文件 -
<ImportFiles>
<ItemHeader FileTypeId="86" ForecastDate="2018-02-01" Version="1" Name="20180201-116_再生品_調整済発注数-Salvage Committed Send Number-86" Status="1" CreatedByName="Amit Vanzari" CreateDate="2018/02/01 17:09:33" UpdatedByName="Amit Vanzari" UpdateDate="2018/02/01 17:09:33" FileNameEN="Salvage Committed Send Number (Daily)" FileNameJP="再生品 調整済発注数" Description="" />
<ItemHeader FileTypeId="86" ForecastDate="2018-02-02" Version="1" Name="20180202-Salvage Committed Send Number" Status="1" CreatedByName="DivakarBabu Lekala" CreateDate="2018/02/02 16:28:59" UpdatedByName="DivakarBabu Lekala" UpdateDate="2018/02/02 16:28:59" FileNameEN="Salvage Committed Send Number (Daily)" FileNameJP="再生品 調整済発注数" Description="" />
<ItemHeader FileTypeId="86" ForecastDate="2018-02-07" Version="1" Name="20180207-116_ Update Delete -Salvage Committed Send Number-" Status="1" CreatedByName="Amit Vanzari" CreateDate="2018/02/07 17:07:59" UpdatedByName="Amit Vanzari" UpdateDate="2018/02/07 17:07:59" FileNameEN="Salvage Committed Send Number (Daily)" FileNameJP="再生品 調整済発注数" Description="" />
</ImportFiles>
我无法理解为什么下面的代码返回null
,其中xml文件有日期 - 2018-02-02
xmlDoc.SelectSingleNode("/ImportFiles/ItemHeader[@ForecastDate = 2018-02-02]")
但它有效 -
xmlDoc.SelectSingleNode("/ImportFiles/ItemHeader[@Version = 1]")
答案 0 :(得分:0)
您有一个日期值,您可能需要在单引号内传递为@ForecastDate = '2018-02-02']
之类的字符串。
所以很可能你需要在单引号中指定它,如xpath中的跟随:
xmlDoc.SelectSingleNode("/ImportFiles/ItemHeader[@ForecastDate = '2018-02-02']");
希望它有效。