Пример #1
0
 public void Test_Settup()
 {
     webRequest = new UfWebRequest();
     string url = "http://www.ufxtract.com/testsuite/hcard/hcard4.htm#uf";
     webRequest.Load(url, UfFormats.HCard());
     nodes = webRequest.Data.Nodes;
 }
 public void Test_Settup()
 {
     webRequest = new UfWebRequest();
     string url = "http://microformats.org/wiki/value-dt-test-YYYY-MM-DD--H-MM-SSpm-EE-NN-UUpm#uf";
     webRequest.Load(url, UfFormats.HCalendar());
     nodes = webRequest.Data.Nodes;
 }
Пример #3
0
        /// <summary>
        /// Finds a node by position from all the nodes with the same name
        /// </summary>
        /// <param name="name">Name to saerch for</param>
        /// <param name="pos">Position in the sub collection created by the search</param>
        /// <returns></returns>
        public UfDataNode GetNameByPosition(string name, int pos)
        {
            UfDataNodes subCollection = new UfDataNodes();

            for (int i = 0; i < this.InnerList.Count; i++)
            {
                UfDataNode testNode = (UfDataNode)this.InnerList[i];
                if (testNode.Name == name)
                {
                    subCollection.Add(testNode);
                }
            }
            if (subCollection.Count >= pos)
            {
                return(subCollection[pos]);
            }
            else
            {
                return(new UfDataNode());
            }
        }
Пример #4
0
 /// <summary>
 /// Finds a node by position from all the nodes with the same name
 /// </summary>
 /// <param name="name">Name to saerch for</param>
 /// <param name="pos">Position in the sub collection created by the search</param>
 /// <returns></returns>
 public UfDataNode GetNameByPosition(string name, int pos)
 {
     UfDataNodes subCollection = new UfDataNodes();
     for (int i = 0; i < this.InnerList.Count; i++)
     {
         UfDataNode testNode = (UfDataNode)this.InnerList[i];
         if (testNode.Name == name)
             subCollection.Add(testNode);
     }
     if( subCollection.Count >= pos )
         return subCollection[pos];
     else
         return new UfDataNode();
 }
Пример #5
0
        /// <summary>
        /// Gets the descendant node using a custom tree expression
        /// </summary>
        /// <param name="treeExpression">Custom expression of a node tree position ie "n/given-name"</param>
        /// <returns>The node or null</returns>
        public UfDataNode DescendantNode(string treeExpression)
        {
            UfDataNode output = new UfDataNode();
            if(treeExpression != "" )
            {
                UfDataNode currentNode = this;
                if (treeExpression.IndexOf('/') > 0)
                {
                    string[] expressions = treeExpression.Split('/');
                    for (int i = 0; i < expressions.Length; i++)
                    {
                        string propertyName = expressions[i];

                        // We are looking for a node from an array
                        if (propertyName.IndexOf('[') > 0)
                        {
                            string[] parts = propertyName.Split('[');
                            propertyName = parts[0];
                            int index = Convert.ToInt32( parts[1].Replace("]","") );

                            UfDataNodes nodeCollection = new UfDataNodes();
                            for (int x = 0; x < currentNode.Nodes.Count; x++)
                            {
                                if (currentNode.Nodes[x].Name == propertyName)
                                    nodeCollection.Add(currentNode.Nodes[x]);
                            }

                            if (nodeCollection.Count > 0)
                            {
                                if (nodeCollection.Count-1 >= index)
                                    currentNode = nodeCollection[index];
                            }

                        }
                        else
                        {
                            // We are looking for a single node
                            if (currentNode.Nodes[propertyName] != null)
                            {
                                currentNode = currentNode.Nodes[propertyName];
                            }
                            else
                            {
                                currentNode = null;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (currentNode.Nodes[treeExpression] != null)
                        currentNode = currentNode.Nodes[treeExpression];

                }
                    if (currentNode != null)
                        output = currentNode;
            }
            return output;
        }
Пример #6
0
        /// <summary>
        /// Gets the descendant node using a custom tree expression
        /// </summary>
        /// <param name="treeExpression">Custom expression of a node tree position ie "n/given-name"</param>
        /// <returns>The node or null</returns>
        public UfDataNode DescendantNode(string treeExpression)
        {
            UfDataNode output = new UfDataNode();

            if (treeExpression != "")
            {
                UfDataNode currentNode = this;
                if (treeExpression.IndexOf('/') > 0)
                {
                    string[] expressions = treeExpression.Split('/');
                    for (int i = 0; i < expressions.Length; i++)
                    {
                        string propertyName = expressions[i];

                        // We are looking for a node from an array
                        if (propertyName.IndexOf('[') > 0)
                        {
                            string[] parts = propertyName.Split('[');
                            propertyName = parts[0];
                            int index = Convert.ToInt32(parts[1].Replace("]", ""));

                            UfDataNodes nodeCollection = new UfDataNodes();
                            for (int x = 0; x < currentNode.Nodes.Count; x++)
                            {
                                if (currentNode.Nodes[x].Name == propertyName)
                                {
                                    nodeCollection.Add(currentNode.Nodes[x]);
                                }
                            }

                            if (nodeCollection.Count > 0)
                            {
                                if (nodeCollection.Count - 1 >= index)
                                {
                                    currentNode = nodeCollection[index];
                                }
                            }
                        }
                        else
                        {
                            // We are looking for a single node
                            if (currentNode.Nodes[propertyName] != null)
                            {
                                currentNode = currentNode.Nodes[propertyName];
                            }
                            else
                            {
                                currentNode = null;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (currentNode.Nodes[treeExpression] != null)
                    {
                        currentNode = currentNode.Nodes[treeExpression];
                    }
                }
                if (currentNode != null)
                {
                    output = currentNode;
                }
            }
            return(output);
        }