PHPackages                             opencat/filter-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. opencat/filter-xml

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

opencat/filter-xml
==================

Generic XML file filter for the OpenCAT Framework

00PHP

Since May 9Pushed 1mo agoCompare

[ Source](https://github.com/shaikhammar/opencat-filter-xml)[ Packagist](https://packagist.org/packages/opencat/filter-xml)[ RSS](/packages/opencat-filter-xml/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

catframework/filter-xml
=======================

[](#catframeworkfilter-xml)

Generic XML file filter for the [CAT Framework](https://github.com/shaikhammar/cat-framework).

Works with any well-formed XML file: Android string resources, app config files, custom XML formats, etc.

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

[](#installation)

```
composer require catframework/filter-xml
```

Usage
-----

[](#usage)

```
use CatFramework\FilterXml\XmlFilter;

$filter = new XmlFilter();

// Extract translatable segments from an XML file
$document = $filter->extract('strings.xml', 'en', 'fr');

foreach ($document->getSegmentPairs() as $pair) {
    echo $pair->source->getPlainText() . PHP_EOL;
    // … send to MT, TM lookup, or human translator …
    $pair->target = new Segment('seg-t', [$translatedText]);
}

// Write the translated XML file
$filter->rebuild($document, 'strings.fr.xml');
```

Extraction heuristic
--------------------

[](#extraction-heuristic)

The filter uses a structural heuristic to decide what to extract:

- **Translatable element** — has at least one non-whitespace direct text node. Its full content (text + any child elements) is extracted as one segment.
- **Container element** — has only element children. Recursed into; not extracted itself.

Child elements inside a translatable segment are represented as `InlineCode` pairs so translators see placeholders (``, ``) rather than raw markup.

**Example** — given:

```

    Hello world

        First item

```

Three segments are extracted: `Hello {}world{}`, `First item`.

Skeleton format
---------------

[](#skeleton-format)

The skeleton stored in `BilingualDocument::$skeleton` is:

```
[
    'xml'     => string,    // full DOMDocument::saveXML() output with tokens in place of segment text
    'seg_map' => [          // segId => token string
        'seg-1' => '{{SEG:001}}',
        'seg-2' => '{{SEG:002}}',
        // …
    ],
]
```

Tokens are valid XML character data, so the skeleton is always parseable XML.

Limitations
-----------

[](#limitations)

- **Generic heuristic**: the filter has no knowledge of application-specific schemas. Elements that should not be translated (e.g. ``, ``) will be extracted if they contain text. For schema-aware extraction, subclass `XmlFilter` and override `walkElement()`.
- **Whitespace-only nodes**: text nodes containing only whitespace (indentation, newlines) are silently skipped.
- **CDATA sections**: treated as text content by the DOM; extracted and re-encoded as regular text on rebuild.
- **XML namespace prefixes** are preserved in `InlineCode` data as-is.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance61

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6b9044413071860fd6199e56c661a24f449797b77a1b130f0df7e98be8481f4?d=identicon)[shaikhammar](/maintainers/shaikhammar)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (3 commits)")

### Embed Badge

![Health badge](/badges/opencat-filter-xml/health.svg)

```
[![Health](https://phpackages.com/badges/opencat-filter-xml/health.svg)](https://phpackages.com/packages/opencat-filter-xml)
```

PHPackages © 2026

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