Example #1
0
 public static object Extract([Implict] Executive engine, object arg, string xpath)
 {
     QueryNode.LispProcessingContext owner = (QueryNode.LispProcessingContext)engine.Owner;
     XmlDataAccessor xmlacc = new XmlDataAccessor();
     if (arg == null)
         return null;
     else if (arg is Resultset)
     {
         Resultset rs = (Resultset)arg;
         Resultset dest = new Resultset(RowType.CreateContainerType(typeof(System.Object)), null);
         if (!dest.RowType.RowTypeEquals(rs.RowType))
             throw new InvalidOperationException();
         while (rs.Begin != null)
         {
             Row row = rs.Dequeue();
             XmlNode node = (XmlNode)row.GetObject(0);
             object name = row.GetValue(1);
             row = dest.NewRow();
             if (node != null)
             {
                 XmlNodeList nodes = node.SelectNodes(xpath,
                     owner.QueryContext.GetNsManager(node.OwnerDocument));
                 if (nodes.Count > 0)
                     row.SetObject(0, nodes);
             }
             row.SetValue(1, name);
             dest.Enqueue(row);
         }
         return dest;
     }
     else if (arg is XmlNode)
     {
         XmlNode node = (XmlNode)arg;
         XmlNodeList nodes = node.SelectNodes(xpath,
             owner.QueryContext.GetNsManager(node.OwnerDocument));
         if (nodes.Count == 0)
             return null;
         else
             return nodes;
     }
     else if (arg is XmlNodeList)
     {
         XmlDataAccessor.NodeList nodeList = new XmlDataAccessor.NodeList();
         foreach (XmlNode node in (XmlNodeList)arg)
         {
             XmlNodeList nodes = node.SelectNodes(xpath,
                 owner.QueryContext.GetNsManager(node.OwnerDocument));
             nodeList.AddRange(nodes);
         }
         if (nodeList.Count > 0)
             return nodeList;
         else
             return null;
     }
     else
         throw new InvalidOperationException();
 }