System.Xml.XmlDataDocument.CreateNavigator C# (CSharp) Méthode

CreateNavigator() protected méthode

protected CreateNavigator ( XmlNode node ) : XPathNavigator
node XmlNode
Résultat XPathNavigator
        protected override XPathNavigator CreateNavigator(XmlNode node)
        {
            Debug.Assert(node.OwnerDocument == this || node == this);
            if (XPathNodePointer.s_xmlNodeType_To_XpathNodeType_Map[(int)(node.NodeType)] == -1)
                return null;
            if (IsTextNode(node.NodeType))
            {
                XmlNode parent = node.ParentNode;
                if (parent != null && parent.NodeType == XmlNodeType.Attribute)
                    return null;
                else
                {
#if DEBUG
                    //if current node is a text node, its parent node has to be foliated
                    XmlBoundElement be = node.ParentNode as XmlBoundElement;
                    if (be != null)
                        Debug.Assert(be.IsFoliated);
#endif
                    XmlNode prevSib = node.PreviousSibling;
                    while (prevSib != null && IsTextNode(prevSib.NodeType))
                    {
                        node = prevSib;
                        prevSib = SafePreviousSibling(node);
                    }
                }
            }
            return new DataDocumentXPathNavigator(this, node);
        }

Usage Example

 /// <summary>
 /// Generates an XPath navigatable dataset based on sql
 /// </summary>
 /// <param name="sql">The SQL to execute</param>
 /// <param name="setName">Name of the returned set</param>
 /// <returns>A <setName></setName> element with the results, or an <error></error> element if an exception occured</returns>
 public static XPathNodeIterator GetDataSet(string sql, string setName)
 {
   try
   {
     DataSet ds = GetDataSetFromSql(sql, setName);
     var dataDoc = new XmlDataDocument(ds);
     return dataDoc.CreateNavigator().Select(".");
   }
   catch (Exception e)
   {
     // If there's an exception we'll output an error element instead
     var errorDoc = new XmlDocument();
     errorDoc.LoadXml(String.Format("<error>{0}</error>", HttpUtility.HtmlEncode(e.ToString())));
     return errorDoc.CreateNavigator().Select(".");
   }
 }
All Usage Examples Of System.Xml.XmlDataDocument::CreateNavigator
XmlDataDocument