Skip to content

Tree traversal

kwasi Denkyira

Asked Apr 20, 2010, 10:06 AM EDT2 answers
Share
LinkedInX
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 Sisodiya
    0
    Hello Kwasi
    Where are your code????
    thanks
    0
  • 0
     
     
     
    //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);
     
     
     
    0