public void ExtractDataAll(Element container) { var allMatchElements = ExtractContainerElements(container); if (allMatchElements != null && allMatchElements.Count > 0) { if (IsReturnCollection()) { string collectKey = GetCollectionKey(); Scope.ScopeId = collectKey; #region 集合直接处理子级 List <Dictionary <string, Object> > colist = new List <Dictionary <string, object> >(); foreach (var subContainer in allMatchElements) { Dictionary <string, Object> collectionItem = new Dictionary <string, object>(); if (childNodes.Count == 0) { ExtractDataByRuleMethods(subContainer); Dictionary <string, Object> nodeScopeObj = Scope.GetContainerObjectIteration(); ExtractScope.MergingScopeObjectWith(nodeScopeObj, collectionItem, true); } else { foreach (ExtractDataNode node in ChildNodes) { node.Scope.ContainerScope = Scope; node.ExtractDataAll(subContainer); Dictionary <string, Object> nodeScopeObj = node.Scope.GetContainerObjectIteration(); ExtractScope.MergingScopeObjectWith(nodeScopeObj, collectionItem, true); } } colist.Add(collectionItem); } Scope.Set(collectKey, colist); #endregion } else { foreach (var element in allMatchElements) { #region 本级处理 if (WhenNodeInContainer(container, element) != false) { ExtractDataByRuleMethods(element); } #endregion #region 子级处理 ExtractChild(element); #endregion if (ExtractFirstOnly() == true) { break; } } } } }
public void ExtractToScope(ExtractScope Scope) { string attrName = GetNotNullAttrValue("name"); string paramName = GetNotNullAttrValue("paramName"); string rawReturn = OperateElement.Attr(attrName); if (IsOperateNode() == false) { Scope.Set(paramName, rawReturn); } else { string opType = GetNotNullAttrValue("op"); if (opType.Equals("Regex", StringComparison.InvariantCultureIgnoreCase)) { string pattern = GetNotNullAttrValue("pattern"); string retVal = GetNotNullAttrValue("retVal"); if (string.IsNullOrEmpty(retVal)) { int groupVal = Convert.ToInt32("0" + GetNotNullAttrValue("retGroup")); Match m = Regex.Match(rawReturn, pattern); if (m.Success && m.Groups.Count > groupVal) { Scope.Set(paramName, m.Groups[groupVal].Value); } } else { Regex RE = new Regex(pattern, RegexOptions.IgnoreCase); Scope.Set(paramName, RE.Replace(rawReturn, retVal)); } } } }
/// <summary> /// 无异常处理 /// </summary> /// <param name="doc"></param> /// <returns></returns> public ExtractDocumentReport ExtractWith(Document doc) { ExtractDocumentReport ret = new ExtractDocumentReport(); try { using (ExecutionContextScope scope = new ExecutionContextScope()) { foreach (ExtractDataNode _node in _extractNodes) { _node.ExtractDataAll(doc); } } } catch (Exception extractEx) { ret.ExtractExcetpion = extractEx; } ret.CurrentExtractResult = ExtractScope.MergingAllScopeObject(); //绑定结果(集) if (DocumentResult != null) { DocumentResult.DataBind(ret.CurrentExtractResult); } return(ret); }
/// <summary> /// 从接口加载抽取文档定义 /// </summary> /// <param name="rule"></param> /// <returns></returns> public static ExtractTaskDocument FromExtractRule(IExtractDocumentRule rule) { ExtractTaskDocument doc = new ExtractTaskDocument(); doc.Scope.ScopeDeepth = 1; doc.Scope.ScopeId = "^"; doc.Scope.ContainerId = null; doc.SrcType = RuleLoadSource.Interface; ExtractScope.MergingScopeObjectWith(rule.StartupArguments(), doc.defaultArgs, true); XmlDocument xmlDoc = rule.RuleDocument(); doc.parseRuleDocument(xmlDoc); return(doc); }
public void DataBind(Dictionary <string, object> result) { ExtractScope.MergingScopeObjectWith(result, scopeResult, true); }