private string AnalyzeTXPath(TXPath txpath, HtmlNode hnPre) { string xpath = txpath.Xpath; string attri = txpath.Attri; string position = txpath.Position; //特别处理 if (xpath.StartsWith("./@")) { string val = hnPre.Attributes[attri].Value; return(val); } HtmlNode hn = hnPre.SelectSingleNode(xpath); if (hn == null) { throw new Exception("xpath position failed " + xpath); } if (attri != null) { string val = hn.Attributes[attri].Value; return(val); } String value = Position(hn, position); return(value); }
private void AnalyzeTField(TField tfield, HtmlNode hn, XmlElement root, XmlDocument xdResult) { string name = tfield.Name; TConst tconst = tfield.TConst; TXPath txpath = tfield.TXPath; TRegex tregex = tfield.TRegex; if (txpath == null) { String valConst = AnalyzeTConst(tconst); AddElement(name, valConst, root, xdResult); return; } String valXpath = AnalyzeTXPath(txpath, hn); if (tregex == null) { AddElement(name, valXpath, root, xdResult); return; } String valRegex = AnalyzeTRegex(tregex, valXpath); AddElement(name, valRegex, root, xdResult); }
private static TXPath GetTXPath(XmlNode xnField) { XmlNode xnXPath = xnField.SelectSingleNode(@"./xpath"); if (xnXPath == null) { return(null); } string xpath = xnXPath.InnerText; XmlNode xnPostion = xnXPath.Attributes["position"]; string position = xnPostion == null ? "innertext" : xnPostion.Value; TXPath tx = new TXPath(xpath, position); return(tx); }
private static TField GetTField(XmlNode xnField) { XmlNode xnName = xnField.SelectSingleNode(@"./name"); if (xnName == null) { throw new Exception("no name tag found"); } string name = xnName.InnerText; TXPath tx = GetTXPath(xnField); TRegex tr = GetTRegex(xnField); TConst tc = GetTConst(xnField); TField tf = new TField(name, tx, tr, tc); return(tf); }