从XPathNodeIterator获取数据
本文关键字:数据 获取 XPathNodeIterator | 更新日期: 2023-09-27 18:26:20
我有一个XPathNodeIterator xpProducts,它包含一个类似的XML
<estocklevel>0</estocklevel>
<weightingram>0</weightingram>
<unit></unit>
<volume>0</volume>
<discountgroup></discountgroup>
<manufactor>31862244</manufactor>
<deliverydate>1900-01-01T00:00:00</deliverydate>
<dayscreated extra="dayscreated">41489</dayscreated>
现在我想在一个字符串中获取每个节点的数据,我已经尝试了一些类似的东西
string strProductID = xpProducts.Current.Select("/manufactor");
但是它抛出了一个错误
Error 3 Cannot implicitly convert type 'System.Xml.XPath.XPathNodeIterator' to 'string' D:'Projects'20-06-2013-Files'App_Code'DataFetcher.cs 55 28 D:'Projects'20-06-2013-Files'
是否无法从XPathNodeIterator中获取字符串数据?
为了获取字符串数据,您需要一个XPathNavigator:
string strProductID = null;
XPathNavigator navProductID = xpProducts.Current.SelectSingleNode("manufactor");
if(navProductID != null)
{
strProductID = navProductID.Value;
}
我还建议使用foreach
循环,而不是MoveNext()
和Current
。