byjg/xmlutil

A powerful and intuitive PHP library for working with XML documents. This utility makes XML manipulation, querying, and conversion simple and straightforward in PHP.

Fund package maintenance!
byjg

Installs: 138 083

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 2

Open Issues: 0

pkg:composer/byjg/xmlutil

5.0.2 2025-07-03 15:33 UTC

This package is auto-updated.

Last update: 2025-11-20 18:44:51 UTC


README

A powerful and intuitive PHP library for working with XML documents. This utility makes XML manipulation, querying, and conversion simple and straightforward in PHP.

Build Status Opensource ByJG GitHub source GitHub license GitHub release

Overview

PHP XML Util provides a comprehensive set of tools for XML manipulation in PHP applications. It simplifies common XML operations with an intuitive API, allowing developers to create, modify, query, and validate XML documents with minimal code.

The library is designed to be lightweight yet powerful, offering features that go beyond PHP's built-in XML functionality while maintaining a clean and easy-to-use interface.

Key Features

  • Simple XML Creation API - Create and manipulate XML documents programmatically with an intuitive API
  • XPath Querying - Easily query and navigate XML documents using XPath expressions
  • PHP Model ↔ XML Conversion - Seamlessly convert between PHP objects and XML representations
  • Attribute-Based Mapping - Use PHP attributes to control XML serialization behavior
  • Namespace Support - Full support for XML namespaces in all operations
  • Document Cleaning - Selectively remove specific tags from XML documents
  • XML Validation - Validate XML documents against schemas
  • File Handling - Convenient methods for loading and saving XML from/to files

Quick Example

<?php
use ByJG\XmlUtil\XmlDocument;

// Create a new XML document
$xml = new XmlDocument('<root />');

// Build the document structure
$myNode = $xml->appendChild('mynode');
$myNode->appendChild('subnode', 'text');
$myNode->appendChild('subnode', 'more text');
$otherNode = $myNode->appendChild('othersubnode', 'other text');
$otherNode->addAttribute('attr', 'value');

// Output formatted XML
echo $xml->toString(format: true);

Output:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <mynode>
    <subnode>text</subnode>
    <subnode>more text</subnode>
    <othersubnode attr="value">other text</othersubnode>
  </mynode>
</root>

Documentation

The library is fully documented with detailed guides and examples for each feature:

Installation

composer require "byjg/xmlutil"

Running Tests

vendor/bin/phpunit

License

MIT

Dependencies

flowchart TD
    byjg/xmlutil --> ext-simplexml
    byjg/xmlutil --> ext-dom
    byjg/xmlutil --> byjg/serializer
Loading

Open source ByJG