PHPackages                             liberu/laravel-gramps-xml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. liberu/laravel-gramps-xml

ActiveLibrary

liberu/laravel-gramps-xml
=========================

A Laravel package for reading and writing XML files.

v1.0.0(2mo ago)2293↓23.5%PHPPHP ^8.3

Since Mar 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/liberu-genealogy/laravel-gramps-xml)[ Packagist](https://packagist.org/packages/liberu/laravel-gramps-xml)[ RSS](/packages/liberu-laravel-gramps-xml/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (11)Used By (0)

laravel-gramps-xml
==================

[](#laravel-gramps-xml)

This package provides easy-to-use services for reading and writing GRAMPS XML files in Laravel applications. It supports the Gramps XML DTD format (version 1.7.2) for genealogical data import and export.

Features
--------

[](#features)

- ✅ Full support for Gramps XML DTD v1.7.2
- ✅ XML validation against official Gramps DTD
- ✅ Comprehensive import/export functionality
- ✅ Parse genealogical data (people, families, events, places, sources, etc.)
- ✅ Create properly formatted Gramps XML files
- ✅ Error handling and validation

Installation
------------

[](#installation)

To install the package, run the following command in your Laravel project:

```
composer require liberu/laravel-gramps-xml
```

Usage
-----

[](#usage)

### XmlReader

[](#xmlreader)

#### Reading and Parsing Gramps XML Files

[](#reading-and-parsing-gramps-xml-files)

```
use LaravelGrampsXml\XmlReader;

$xmlReader = new XmlReader();

try {
    // Read and parse Gramps XML file
    $data = $xmlReader->parseGrampsXml('path/to/your/file.gramps');

    // Access parsed data
    print_r($data['people']);      // Array of people
    print_r($data['families']);    // Array of families
    print_r($data['events']);      // Array of events
    print_r($data['places']);      // Array of places
    print_r($data['sources']);     // Array of sources

} catch (Exception $e) {
    echo "Error reading XML file: " . $e->getMessage();
}
```

#### Reading Raw XML

[](#reading-raw-xml)

```
use LaravelGrampsXml\XmlReader;

$xmlReader = new XmlReader();

try {
    // Get raw SimpleXMLElement object
    $xml = $xmlReader->read('path/to/your/file.gramps');

    // Access XML elements directly
    foreach ($xml->people->person as $person) {
        echo $person->name->first . " " . $person->name->surname . "\n";
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

#### Validating XML Against DTD

[](#validating-xml-against-dtd)

```
use LaravelGrampsXml\XmlReader;

$xmlReader = new XmlReader();

try {
    // Read and validate against Gramps DTD
    $xml = $xmlReader->readAndValidate('path/to/your/file.gramps');
    echo "XML is valid!\n";
} catch (Exception $e) {
    echo "Validation error: " . $e->getMessage();
}
```

### XmlWriter

[](#xmlwriter)

#### Creating and Writing Gramps XML Files

[](#creating-and-writing-gramps-xml-files)

```
use LaravelGrampsXml\XmlWriter;

$xmlWriter = new XmlWriter();

// Define genealogical data
$data = [
    'people' => [
        [
            'handle' => 'person001',
            'id' => 'I0001',
            'gender' => 'M',
            'name' => [
                'type' => 'Birth Name',
                'first' => 'John',
                'surname' => 'Doe',
            ],
        ],
    ],
    'families' => [
        [
            'handle' => 'family001',
            'id' => 'F0001',
            'father' => 'person001',
            'mother' => 'person002',
        ],
    ],
    'events' => [
        [
            'handle' => 'event001',
            'id' => 'E0001',
            'type' => 'Birth',
            'description' => 'Birth of John Doe',
        ],
    ],
];

try {
    // Create Gramps XML
    $xmlContent = $xmlWriter->createGrampsXml($data);

    // Write to file
    $xmlWriter->write('output.gramps', $xmlContent);

    echo "Gramps XML file created successfully!\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

#### Validating XML Content

[](#validating-xml-content)

```
use LaravelGrampsXml\XmlWriter;

$xmlWriter = new XmlWriter();

try {
    $xmlContent = $xmlWriter->createGrampsXml($data);

    // Validate the XML content against the Gramps DTD
    if ($xmlWriter->validateXmlContent($xmlContent)) {
        echo "XML content is valid according to Gramps DTD!\n";
        $xmlWriter->write('validated-output.gramps', $xmlContent);
    }
} catch (Exception $e) {
    echo "Validation error: " . $e->getMessage();
}
```

### Using Service Classes

[](#using-service-classes)

The package also provides service classes in the `Services` namespace that extend the base functionality:

```
use LaravelGrampsXml\Services\XmlReader;
use LaravelGrampsXml\Services\XmlWriter;

// Reader service - returns parsed array data by default
$readerService = new XmlReader();
$importData = $readerService->import('path/to/file.gramps');

echo "Imported {$importData['stats']['people_count']} people\n";
echo "Imported {$importData['stats']['families_count']} families\n";

// Writer service - handles both array and string content
$writerService = new XmlWriter();
$writerService->write('output.gramps', $data);
```

Gramps XML Format
-----------------

[](#gramps-xml-format)

This package implements the Gramps XML DTD version 1.7.2. The DTD file is included in the package at `dtd/grampsxml.dtd`.

### Supported Elements

[](#supported-elements)

- **Header**: Database metadata and researcher information
- **People**: Individual persons with names, gender, events, etc.
- **Families**: Family units with relationships
- **Events**: Life events (birth, death, marriage, etc.)
- **Places**: Geographic locations
- **Sources**: Source documents and references
- **Citations**: Citations to sources
- **Repositories**: Archives and repositories
- **Notes**: Textual notes and annotations
- **Tags**: Categorization tags

Error Handling
--------------

[](#error-handling)

The package throws exceptions for various error conditions:

- `Exception`: File not found, write failures, DTD validation errors
- `InvalidArgumentException`: XML parsing errors

Always wrap your code in try-catch blocks to handle errors gracefully.

License
-------

[](#license)

This package is open-source software licensed under the MIT license.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance83

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 54.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

86d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1044631cf8ee52f2755884210a2129d0a626e5c9616de7ab06608e83510e4204?d=identicon)[delicatacurtis](/maintainers/delicatacurtis)

---

Top Contributors

[![sweep-ai-deprecated[bot]](https://avatars.githubusercontent.com/in/307814?v=4)](https://github.com/sweep-ai-deprecated[bot] "sweep-ai-deprecated[bot] (23 commits)")[![curtisdelicata](https://avatars.githubusercontent.com/u/179251?v=4)](https://github.com/curtisdelicata "curtisdelicata (13 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (5 commits)")[![delicatacurtis](https://avatars.githubusercontent.com/u/247246500?v=4)](https://github.com/delicatacurtis "delicatacurtis (1 commits)")

### Embed Badge

![Health badge](/badges/liberu-laravel-gramps-xml/health.svg)

```
[![Health](https://phpackages.com/badges/liberu-laravel-gramps-xml/health.svg)](https://phpackages.com/packages/liberu-laravel-gramps-xml)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
