예제 #1
0
        private static void CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(MockRepository mocks, XmlReader reader)
        {
            Expect.Call(reader.AttributeCount).Return(3);

            ICloneable cloneable = reader as ICloneable;

            Assert.NotNull(cloneable);

            Expect.Call(cloneable.Clone()).Return(reader);

            IHasXmlNode hasXmlNode = reader as IHasXmlNode;

            Assert.NotNull(hasXmlNode);

            XmlNode node = new XmlDocument();

            Expect.Call(hasXmlNode.GetNode()).Return(node);

            mocks.ReplayAll();

            Assert.Equal(3, reader.AttributeCount);
            Assert.Equal(node, hasXmlNode.GetNode());

            Assert.Same(cloneable, cloneable.Clone());

            mocks.VerifyAll();
        }
예제 #2
0
        public override object Evaluate(BaseIterator iter)
        {
            IHasXmlNode xn = iter.Current as IHasXmlNode;

            if (xn == null)
            {
                return(String.Empty);
            }
            XmlNode n = xn.GetNode();

            if (n.OwnerDocument == null)
            {
                return(String.Empty);
            }
            XmlDocumentType doctype = n.OwnerDocument.DocumentType;

            if (doctype == null)
            {
                return(String.Empty);
            }
            XmlEntity ent = doctype.Entities.GetNamedItem(arg0.EvaluateString(iter)) as XmlEntity;

            if (ent == null)
            {
                return(String.Empty);
            }
            return(ent.SystemId != null ? ent.SystemId : String.Empty);
        }
예제 #3
0
        public static IEnumerable Select(object container, string xPath, IXmlNamespaceResolver resolver)
        {
            if (xPath == null || xPath.Length == 0)
            {
                throw new ArgumentNullException("xPath");
            }

            IXPathNavigable factory = container as IXPathNavigable;

            if (factory == null)
            {
                throw new ArgumentException("container");
            }

            XPathNodeIterator itr = factory.CreateNavigator().Select(xPath, resolver);
            ArrayList         ret = new ArrayList();

            while (itr.MoveNext())
            {
                IHasXmlNode nodeAccessor = itr.Current as IHasXmlNode;
                if (nodeAccessor == null)
                {
                    throw new InvalidOperationException();
                }
                ret.Add(nodeAccessor.GetNode());
            }
            return(ret);
        }
        public override object Evaluate(BaseIterator iter)
        {
            IHasXmlNode hasXmlNode = iter.Current as IHasXmlNode;

            if (hasXmlNode == null)
            {
                return(string.Empty);
            }
            XmlNode node = hasXmlNode.GetNode();

            if (node.OwnerDocument == null)
            {
                return(string.Empty);
            }
            XmlDocumentType documentType = node.OwnerDocument.DocumentType;

            if (documentType == null)
            {
                return(string.Empty);
            }
            XmlEntity xmlEntity = documentType.Entities.GetNamedItem(this.arg0.EvaluateString(iter)) as XmlEntity;

            if (xmlEntity == null)
            {
                return(string.Empty);
            }
            return((xmlEntity.SystemId == null) ? string.Empty : xmlEntity.SystemId);
        }
        private static void CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(XmlReader reader)
        {
            reader.Expect(x => x.AttributeCount).Return(3);

            ICloneable cloneable = reader as ICloneable;

            Assert.NotNull(cloneable);

            cloneable.Expect(x => x.Clone()).Return(reader);

            IHasXmlNode hasXmlNode = reader as IHasXmlNode;

            Assert.NotNull(hasXmlNode);

            XmlNode node = new XmlDocument();

            hasXmlNode.Expect(x => x.GetNode()).Return(node);

            Assert.Equal(3, reader.AttributeCount);
            Assert.Equal(node, hasXmlNode.GetNode());

            Assert.Same(cloneable, cloneable.Clone());

            reader.VerifyAllExpectations();
        }
        public static IEnumerable Select(object container, string xPath, IXmlNamespaceResolver resolver)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (string.IsNullOrEmpty(xPath))
            {
                throw new ArgumentNullException("xPath");
            }
            ArrayList       list      = new ArrayList();
            IXPathNavigable navigable = container as IXPathNavigable;

            if (navigable == null)
            {
                throw new ArgumentException(System.Web.SR.GetString("XPathBinder_MustBeIXPathNavigable", new object[] { container.GetType().FullName }));
            }
            XPathNodeIterator iterator = navigable.CreateNavigator().Select(xPath, resolver);

            while (iterator.MoveNext())
            {
                IHasXmlNode current = iterator.Current as IHasXmlNode;
                if (current == null)
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("XPathBinder_MustHaveXmlNodes"));
                }
                list.Add(current.GetNode());
            }
            return(list);
        }
예제 #7
0
        public static IEnumerable Select(object container, string xPath, IXmlNamespaceResolver resolver)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (String.IsNullOrEmpty(xPath))
            {
                throw new ArgumentNullException("xPath");
            }

            ArrayList results = new ArrayList();

            IXPathNavigable node = container as IXPathNavigable;

            if (node == null)
            {
                throw new ArgumentException(SR.GetString(SR.XPathBinder_MustBeIXPathNavigable, container.GetType().FullName));
            }
            XPathNavigator    navigator = node.CreateNavigator();
            XPathNodeIterator iterator  = navigator.Select(xPath, resolver);

            while (iterator.MoveNext())
            {
                IHasXmlNode hasXmlNode = iterator.Current as IHasXmlNode;
                if (hasXmlNode == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.XPathBinder_MustHaveXmlNodes));
                }
                results.Add(hasXmlNode.GetNode());
            }

            return(results);
        }
예제 #8
0
 /// <summary>
 /// Reads the entire iterator.
 /// </summary>
 private void ReadToEnd()
 {
     while (_iterator.MoveNext())
     {
         IHasXmlNode node = _iterator.Current as IHasXmlNode;
         // Check IHasXmlNode interface.
         if (node == null)
         {
             throw new ArgumentException(Properties.Resources.XmlNodeListFactory_IHasXmlNodeMissing);
         }
         _nodes.Add(node.GetNode());
     }
     _done = true;
 }
예제 #9
0
파일: NodeList.cs 프로젝트: semyonc/xpath2
        public static XmlNode ToXmlNode(XPathNavigator nav)
        {
            IHasXmlNode hasNode = nav as IHasXmlNode;

            if (hasNode != null)
            {
                XmlNode node = hasNode.GetNode();
                if (node != null)
                {
                    return(node);
                }
            }
            return(null);
        }
예제 #10
0
        private DOMNodeList IteratorToList(XPathNodeIterator iterator)
        {
            DOMNodeList list = new DOMNodeList();

            while (iterator.MoveNext())
            {
                IHasXmlNode has_node = iterator.Current as IHasXmlNode;
                if (has_node != null)
                {
                    var node = DOMNode.Create(has_node.GetNode());
                    if (node != null)
                    {
                        list.AppendNode(node);
                    }
                }
            }

            return(list);
        }
예제 #11
0
 /// <summary>
 /// Reads up to the specified index, or until the
 /// iterator is consumed.
 /// </summary>
 private void ReadTo(int to)
 {
     while (_nodes.Count <= to)
     {
         if (_iterator.MoveNext())
         {
             IHasXmlNode node = _iterator.Current as IHasXmlNode;
             // Check IHasXmlNode interface.
             if (node == null)
             {
                 throw new ArgumentException(SR.XmlNodeListFactory_IHasXmlNodeMissing);
             }
             _nodes.Add(node.GetNode());
         }
         else
         {
             _done = true;
             return;
         }
     }
 }
예제 #12
0
        private XmlNode GetNode(XPathNavigator n)
        {
            IHasXmlNode iHasNode = ( IHasXmlNode )n;

            return(iHasNode.GetNode());
        }
예제 #13
0
        /// <summary>
        /// Extracts the XmlNode provided an XPathNavigator object
        /// </summary>
        /// <param name="nav">The XPathNavigator</param>
        /// <returns></returns>
        private XmlNode GetXmlNode(XPathNavigator nav)
        {
            IHasXmlNode node = nav as IHasXmlNode;

            return(node.GetNode());
        }
예제 #14
0
        // Function to execute a specified user-defined XPath
        // extension function at run time.
        public object Invoke(XsltContext Context, object[] Args, XPathNavigator DocContext)
        {
            string            strOne  = null;
            string            strTwo  = null;
            XPathNodeIterator Node    = null;
            IHasXmlNode       objThis = null;
            XmlNode           ndxThis = null;

            // Working node

            switch (m_FunctionName)
            {
            case "CountChar":
                return(CountChar((XPathNodeIterator)Args[0], Convert.ToChar(Args[1])));

            case "FindTaskBy":
                return(FindTaskBy((XPathNodeIterator)Args[0], Convert.ToString(Args[1].ToString())));

            case "Left":
                String sLeftArg0 = Convert.ToString(Args[0]);
                int    iLeftArg1 = Convert.ToInt32(Args[1]);
                return(sLeftArg0.Substring(0, iLeftArg1));

            case "Right":
                String sRightArg0 = Convert.ToString(Args[0]);
                int    iRightArg1 = Convert.ToInt32(Args[1]);
                return(sRightArg0.Substring(sRightArg0.Length - iRightArg1));

            case "verntoenglish":
            case "VernToEnglish":
                if ((object.ReferenceEquals(Args[0].GetType(), System.Type.GetType("System.String"))))
                {
                    strOne = Convert.ToString(Args[0].ToString());
                }
                else
                {
                    Node = (XPathNodeIterator)Args[0];
                    Node.MoveNext();
                    strOne = Node.Current.Value;
                }
                return(VernToEnglish(strOne));

            case "Like":
            case "matches":
                if ((object.ReferenceEquals(Args[0].GetType(), System.Type.GetType("System.String"))))
                {
                    strOne = Convert.ToString(Args[0].ToString());
                }
                else
                {
                    Node = (XPathNodeIterator)Args[0];
                    // Move to the first selected node
                    // See "XpathNodeIterator Class":
                    //     An XPathNodeIterator object returned by the XPathNavigator class is not positioned on the first node
                    //     in a selected set of nodes. A call to the MoveNext method of the XPathNodeIterator class must be made
                    //     to position the XPathNodeIterator object on the first node in the selected set of nodes.
                    Node.MoveNext();
                    // Get the value of this attribute or node
                    strOne = Node.Current.Value;
                    //' Check the kind of node we have
                    //Select Case Node.Current.Name
                    //  Case "eTree"
                    //    ' Get the @Label
                    //    strOne = Node.Current.GetAttribute("Label", "")
                    //  Case "eLeaf"
                    //    Node.MoveNext()
                    //    ' Get the @Text
                    //    strOne = Node.Current.GetAttribute("Text", "")
                    //    strOne = Node.CurrentPosition
                    //  Case "Feature"
                    //    ' Get the @Value
                    //    strOne = Node.Current.GetAttribute("Value", "")
                    //  Case "Result"
                    //    ' Since nothing is specified, I really do not know which of the features to take...
                    //    strOne = ""
                    //  Case Else
                    //    strOne = ""
                    //End Select
                }
                // If (InStr(strOne, "some") > 0) Then Stop

                strTwo = Convert.ToString(Args[1]);
                return(DoLike(strOne, strTwo));

            case "DepType":
            case "deptype":
                // ndxThis = DirectCast(Args(0), XmlNode)
                Node = (XPathNodeIterator)Args[0];
                Node.MoveNext();
                objThis = (IHasXmlNode)Node.Current;
                ndxThis = objThis.GetNode();
                //ndxThis = DirectCast(Node.Current, XmlNode)
                return(DepType(ref ndxThis));

            case "LabelExtNum":
            case "labelnum":
                // ndxThis = DirectCast(Args(0), XmlNode)
                Node = (XPathNodeIterator)Args[0];
                Node.MoveNext();
                objThis = (IHasXmlNode)Node.Current;
                ndxThis = objThis.GetNode();
                //ndxThis = DirectCast(Node.Current, XmlNode)
                return(LabelExtNum(ref ndxThis));

            default:

                break;
            }
            // Return Nothing for unknown function name.
            return(null);
        }