Skip to content

Commit 6e7cabb

Browse files
authored
Merge pull request #3 from ateeducacion/main
Added function to export JSON and extract Metadata
2 parents 31c1226 + 4581170 commit 6e7cabb

10 files changed

Lines changed: 1205 additions & 3 deletions

File tree

.github/workflows/docs.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ on:
55
push:
66
branches:
77
- main # Or the branch you use for documentation
8-
pull_request:
9-
paths:
10-
- "docs/**" # Only trigger if there are changes in the documentation folder
118

129
jobs:
1310
build-docs:

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Simple, fast, and extension-free parser for eXeLearning project files
2222
- Extract text content from XML
2323
- Detect file version
2424
- Extract entire .elp file contents
25+
- Retrieve full metadata tree
2526
- No external extensions required
2627
- Lightweight and easy to use (less than 4 KB footprint library)
2728
- Compatible with PHP 8.0 to PHP 8.5
@@ -98,6 +99,12 @@ $data = $parser->toArray();
9899

99100
// JSON serialization
100101
$jsonData = json_encode($parser);
102+
103+
// Export directly to a JSON file
104+
$parser->exportJson('path/to/output.json');
105+
106+
// Retrieve full metadata as array
107+
$meta = $parser->getMetadata();
101108
```
102109

103110
## Error Handling

docs/api.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ JSON serialization method implementing JsonSerializable interface.
100100

101101
- **Returns:** mixed - Data to be JSON serialized
102102

103+
#### `exportJson(?string $destinationPath = null): string`
104+
105+
Export parsed data to JSON. If a destination path is provided, the JSON will be written to that file.
106+
107+
- **Parameters:**
108+
- `$destinationPath` (string|null): Optional file path for the JSON output
109+
- **Throws:** `Exception` if the JSON cannot be written
110+
- **Returns:** string - JSON representation of the parsed data
111+
112+
#### `getMetadata(): array`
113+
114+
Return a detailed metadata array containing Package, Dublin Core, LOM and LOM-ES
115+
information together with the page tree.
116+
117+
- **Throws:** `Exception` if the XML cannot be parsed
118+
- **Returns:** array - Metadata and content structure
119+
103120
#### `extract(string $destinationPath): void`
104121

105122
Extract contents of an ELP file to a specified directory.

docs/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ELP Parser is a PHP library designed to parse and extract content from ELP (eXe
66

77
- Parse ELP files (both version 2 and 3 supported)
88
- Extract metadata like title, description, author, etc.
9+
- Retrieve a complete metadata tree
910
- Access learning resource information
1011
- Extract package contents to a specified directory
1112
- JSON serialization support
@@ -133,6 +134,17 @@ $data = $parser->toArray();
133134
$json = json_encode($parser);
134135
```
135136

137+
#### Exporting to a JSON file
138+
139+
You can directly export the parsed data to a JSON file using `exportJson()`:
140+
141+
```php
142+
$parser->exportJson('path/to/output.json');
143+
144+
// Obtain a metadata tree
145+
$meta = $parser->getMetadata();
146+
```
147+
136148
### Version Compatibility
137149

138150
The library supports both version 2 and version 3 of ELP files. The parsing process automatically detects the version and handles the content appropriately.

0 commit comments

Comments
 (0)