【问题标题】:Get data from XPathNodeIterator从 XPathNodeIterator 获取数据
【发布时间】:2013-08-05 07:12:42
【问题描述】:

我有一个 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 中是否无法获取字符串数据?

【问题讨论】:

    标签: c# asp.net xml xslt


    【解决方案1】:

    为了获取字符串数据,你需要一个 XPathNavigator:

    string strProductID = null;
    XPathNavigator navProductID = xpProducts.Current.SelectSingleNode("manufactor");
    if(navProductID != null)
    {
      strProductID = navProductID.Value;
    }
    

    我还建议使用foreach 循环而不是MoveNext()Current

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 2013-10-11
      • 2011-02-24
      • 2013-01-30
      • 2015-03-26
      相关资源
      最近更新 更多