Skip to content

Commit

Permalink
Add the table class and rewrite Parser to improve XPath usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Sep 27, 2023
1 parent 556a8a1 commit 9ea9a39
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 67 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All Notable changes to `bakame/html-table` will be documented in this file.

## [0.3.0](https://github.com/bakame-php/html-table/compare/0.2.0...0.3.0) - 2023-09-27

### Added

- `Parser::tableXpathPosition`
- `Table` class which implements the `TabularDataReader` interface.

### Fixed

- Improve identifier validation for `Parser::tablePosition`
- Remove the `$tableOffset` property.

### Deprecated

- None

### Removed

- None

## [0.2.0](https://github.com/bakame-php/html-table/compare/0.1.0...0.2.0) - 2023-09-26

### Added
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ It is possible to configure the parser to improve HTML table resolution:

### tablePosition

Tells which table to parse in the HTML page: If the single argument is
Select the table to parse in the HTML page: If the single argument is

- a string; it will represent the value of the table "id" attribute.
- a positive integer or `0`; it will represent the table offset.
Expand All @@ -83,6 +83,23 @@ $parser = Parser::new()->tablePosition('table-id'); // parse the <table id='tabl
$parser = Parser::new()->tablePosition(3); // parse the 4th table of the page
```
### tableXpathPosition
**Added in version 0.3**
Select the table to parse in the HTML page using a xpath expression. If the expression
is invalid a `ParserError` exception will be thrown. If the expression is valid, the
first result of the expression will be returned.
```php
use Bakame\HtmlTable\Parser;
$parser = Parser::new()->tableXPathPosition('//table');
```
If you use `tableXpathPosition` and `tablePosition` override each other. It is recommended
to use one or the other but not both at the same time.
### ignoreTableHeader and resolveTableHeader
Tells the parser to attempt or not table header resolution.
Expand Down Expand Up @@ -189,6 +206,17 @@ By default, when calling the `Parser::new()` named constructor you will:
- ignore XML errors.
- no formatter is attached to the parser.
### parseHtml and parseFile
Once set you can use `parseHtml` or `parseFile` to extract and parse your table. If parsing
is not possible a `ParseError` exception will be thrown.
Both methods returns a `Table` class which extends `League\Csv\ResultSet` class by adding the
possibility to access the table caption value if present using the `getCaption` method.
Of note the `getCaption` is only accessible on the `Tabble` instance once you start filtering
## Testing
The library:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"league/csv": "^9.6.0"
"league/csv": "^9.11.0"
},
"require-dev": {
"ext-xdebug": "*",
Expand Down
Loading

0 comments on commit 9ea9a39

Please sign in to comment.