DevTreks.Data/EditHelpers/XmlIO.cs
/// <summary>
/// Append shallow cloned children of the navigator to the element
/// use descendentDepth to recurse to grandchildren ...
/// </summary>
/// <param name="nav"></param>
/// <param name="sDeepClone"></param>
/// <param name="parentElement"></param>
Append shallow cloned children of the navigator to the element
use descendentDepth to recurse to grandchildren
Append shallow cloned children of the navigator to the element use descendentDepth to recurse to grandchildren
public static void AppendChildren(XPathNavigator nav, bool deepClone,
            ref XmlElement parentNode, int descendentDepth)
        {
            if (nav.HasChildren == true)
            {
                descendentDepth--;
                XPathNodeIterator oChildrenIterator = nav.SelectChildren(XPathNodeType.Element);
                while (oChildrenIterator.MoveNext())
                {
                    XmlElement oChildElement = null;
                    if (oChildrenIterator.Current.LocalName == Helpers.GeneralHelpers.ROOT_PATH)
                    {
                        oChildElement = (XmlElement)((IHasXmlNode)oChildrenIterator.Current).GetNode().CloneNode(true);
                    }
                    else
                    {
                        oChildElement = (XmlElement)((IHasXmlNode)oChildrenIterator.Current).GetNode().CloneNode(deepClone);
                    }
                    if (oChildElement != null)
                    {
                        bool bIsAnnuity = IsAnnuityElement(oChildElement);
                        if (bIsAnnuity == false)
                        {
                            if (descendentDepth == 0
                                || oChildrenIterator.Current.LocalName == Helpers.GeneralHelpers.ROOT_PATH)
                            {
                                parentNode.AppendChild(oChildElement);
                            }
                            else
                            {
                                AppendChildren(oChildrenIterator.Current.CreateNavigator(), 
                                    deepClone, ref oChildElement, descendentDepth);
                                parentNode.AppendChild(oChildElement);
                            }
                        }
                        else
                        {
                            XmlElement oAnnuityElement = (XmlElement)((IHasXmlNode)oChildrenIterator.Current).GetNode().CloneNode(true);
                            if (descendentDepth == 0)
                            {
                                parentNode.AppendChild(oAnnuityElement);
                            }
                            else
                            {
                                AppendChildren(oChildrenIterator.Current.CreateNavigator(), 
                                    deepClone, ref oChildElement, descendentDepth);
                                parentNode.AppendChild(oChildElement);
                            }
                        }
                    }
                }
            }
        }
public static void AppendChildren ( XPathNavigator nav , bool deepClone , ref XmlElement parentNode , int descendentDepth ) { if ( nav . HasChildren == true ) { descendentDepth -- ; XPathNodeIterator oChildrenIterator = nav . SelectChildren ( XPathNodeType . Element ) ; while ( oChildrenIterator . MoveNext ( ) ) { XmlElement oChildElement = null ; if ( oChildrenIterator . Current . LocalName == Helpers . GeneralHelpers . ROOT_PATH ) { oChildElement = ( XmlElement ) ( ( IHasXmlNode ) oChildrenIterator . Current ) . GetNode ( ) . CloneNode ( true ) ; } else { oChildElement = ( XmlElement ) ( ( IHasXmlNode ) oChildrenIterator . Current ) . GetNode ( ) . CloneNode ( deepClone ) ; } if ( oChildElement != null ) { bool bIsAnnuity = IsAnnuityElement ( oChildElement ) ; if ( bIsAnnuity == false ) { if ( descendentDepth == 0 || oChildrenIterator . Current . LocalName == Helpers . GeneralHelpers . ROOT_PATH ) { parentNode . AppendChild ( oChildElement ) ; } else { AppendChildren ( oChildrenIterator . Current . CreateNavigator ( ) , deepClone , ref oChildElement , descendentDepth ) ; parentNode . AppendChild ( oChildElement ) ; } } else { XmlElement oAnnuityElement = ( XmlElement ) ( ( IHasXmlNode ) oChildrenIterator . Current ) . GetNode ( ) . CloneNode ( true ) ; if ( descendentDepth == 0 ) { parentNode . AppendChild ( oAnnuityElement ) ; } else { AppendChildren ( oChildrenIterator . Current . CreateNavigator ( ) , deepClone , ref oChildElement , descendentDepth ) ; parentNode . AppendChild ( oChildElement ) ; } } } } } }
Append shallow cloned children of the navigator to the element
use descendentDepth to recurse to grandchildren ...
Append shallow cloned children of the navigator to the element use descendentDepth to recurse to grandchildren ...
//clone the children //decrease descendent depth by one //xmldoc els are always deeply cloned (or the document model can get out of shape) //annuity nodes must be deep cloned //always append deep cloned element
nav
XPathNavigator
None
deepClone
bool
XmlElement
ref
descendentDepth
int
sDeepClone
None
parentElement
None