0
我正在解析一個Xml文件。我在C#2.0中如何使用更合理的XPathNodeIterator
MoveNext()
遇到了麻煩。關於C#中XPathNodeIterator問題的問題#
我的代碼,因爲這,
while (it.MoveNext())
{
string str = it.Current.GetAttribute("id", it.Current.NamespaceURI);
it.Current.MoveToChild("item", "");
// do someting....
// My XMl file is a complex Xml file. I must Move to multi layer Child with *MoveToChild()*.
// After that, I must add several *MoveToParent()* in different Layers to make sure the *it* still meet for the use of while loop.
// I think it doesn't make sense like this.
// Some time. the *it* can't still direct to my original layer. While-Loop doesn't work well.
}
我試圖聲明一個新創建XPathNodeIterator對象tempIt因爲這樣,
while (it.MoveNext())
{
XPathNodeIterator tempIt;
tempIt= it;
string str = tempIt.Current.GetAttribute("id", tempIt.Current.NamespaceURI);
tempIt.Current.MoveToChild("item", "");
// Now I chech *it* on here, I found the *it* also changed it's *current* and "position". and it's count also changed.
// I don't know why.
}
我怎樣才能解決這個問題?
讚賞您的意見和建議。
您已經創建創建XPathNodeIterator,然後你使用DOM風格的導航 - 使用選擇方法和學習的XPath。你只需要一個迭代器。 – annakata 2010-12-23 09:35:08