Tree traversal
I am trying to search a xml documents. I can traverse the source document all the way down to the last child. For some reasons, the destination xml document can not traverse to the bottom like the source. please see code. Error shows Red line.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Apr 20, 2010, 10:00 PM EDT
Where are your code????
thanks
kwasi Denkyira2 pointsPosted Apr 21, 2010, 3:04 AM EDT
//XPathDocument src = new XPathDocument(oSrcAllXMLReader);
XPathNavigator srcnav = oSrcXMLDoc.CreateNavigator();
//XPathDocument des = new XPathDocument(oDesXMLReader);
XPathNavigator desnav = oDesXmlDoc.CreateNavigator();
MessageBox.Show(desnav.OuterXml);
srcnav.MoveToRoot();
srcnav.MoveToFirstChild();
do
{
do
{
desnav.MoveToRoot();
desnav.MoveToFirstChild();
Boolean found = false;
do
{
do
{
if (srcnav.Name == desnav.Name)
{
string tmpval = srcnav.Value.ToString();
if (tmpval != null && tmpval.Length > 0)
{
desnav.SetValue(tmpval);
}
found = true;
}
} while (desnav.MoveToChild(XPathNodeType.Element) && found == false);
} while (desnav.MoveToNext(XPathNodeType.Element) && found == false);
} while (srcnav.MoveToChild(XPathNodeType.Element));
} while (srcnav.MoveToNext(XPathNodeType.Element));
MessageBox.Show(desnav.OuterXml);