0

I have an XPathNodeIterator xpProducts and it holds an XML like this

<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>

Now I want to get each nodes data in a string ,I have tried some thing like this

 string  strProductID = xpProducts.Current.Select("/manufactor");

but it throws an error

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\

Is it impossible to get string data out of XPathNodeIterator ?

1 Answer 1

1

In order to get string data, you need an XPathNavigator:

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

I would also recommend using a foreach loop rather than MoveNext() and Current.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.