public void GetIndices() { HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]"); var e = myDocument.GetElementByPath(path); Assert.AreEqual(1, HtmlTable.GetColumnIndex(e)); Assert.AreEqual(6, HtmlTable.GetRowIndex(e)); Assert.AreEqual(e, HtmlTable.GetEmbeddingTD(e)); Assert.AreEqual(e.Parent, HtmlTable.GetEmbeddingTR(e)); }
/// <summary> /// Gets the HtmlTable the given path is pointing to. /// If the path is pointing into a table, the embedding table is returned. /// If the path is not pointing to a table element null is returned. /// </summary> public static HtmlTable GetByPath(IHtmlDocument doc, HtmlPath path) { var start = doc.GetElementByPath(path); if (start == null) { return(null); } return(GetByElement(start)); }
/// <summary> /// Gets the HtmlTable the given path is pointing to. /// If the path is pointing into a table, the embedding table is returned. /// If the path is not pointing to a table element null is returned. /// </summary> public static HtmlTable GetTableByPath(this IHtmlDocument doc, HtmlPath path) { var start = doc.GetElementByPath(path); if (start == null) { return(null); } return(start.FindEmbeddingTable()); }
/// <summary> /// Gets the text of the element specified by the given <see cref="HtmlPath"/>. /// </summary> public static string GetTextByPath(this IHtmlDocument doc, HtmlPath path) { var e = doc.GetElementByPath(path); if (e == null) { return(null); } return(e.InnerText); }
public DataTable ExtractTable() { var pathSeriesDescriptor = myDescriptor as PathSeriesDescriptor; if (pathSeriesDescriptor != null) { var table = ExtractTable(myDocument, HtmlPath.Parse(pathSeriesDescriptor.Path)); return(TableFormatter.ToFormattedTable(pathSeriesDescriptor, table)); } var pathTableDescriptor = myDescriptor as PathTableDescriptor; if (pathTableDescriptor != null) { var table = ExtractTable(myDocument, HtmlPath.Parse(pathTableDescriptor.Path)); return(TableFormatter.ToFormattedTable(pathTableDescriptor, table)); } var pathCellDescriptor = myDescriptor as PathCellDescriptor; if (pathCellDescriptor != null) { var table = ExtractTable(myDocument, HtmlPath.Parse(pathCellDescriptor.Path)); var value = TableFormatter.GetValue(pathCellDescriptor, table); // XXX: this is really ugly - i have to create a table just to satisfy the interface :( return(CreateTableForScalar(pathCellDescriptor.ValueFormat.Type, value)); } var pathSingleValueDescriptor = myDescriptor as PathSingleValueDescriptor; if (pathSingleValueDescriptor != null) { var e = myDocument.GetElementByPath(HtmlPath.Parse(pathSingleValueDescriptor.Path)); var str = e == null ? null : e.InnerText; var value = pathSingleValueDescriptor.ValueFormat.Convert(str); // XXX: this is really ugly - i have to create a table just to satisfy the interface :( return(CreateTableForScalar(pathSingleValueDescriptor.ValueFormat.Type, value)); } throw new NotSupportedException("Format not supported for Html documents: " + myDescriptor.GetType()); }
public void GetRoot() { HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]"); var e = myDocument.GetElementByPath(path); Assert.AreEqual("TD", e.TagName); Assert.AreEqual("HTML", e.GetRoot().TagName); }