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
Requires
- php: >=8.1 <8.4
- ext-dom: *
- ext-libxml: *
- ext-simplexml: *
- byjg/serializer: ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.6
- vimeo/psalm: ^5.20
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.
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:
- Creating XML Documents: Learn how to create and manipulate XML documents using the API
- Working with Namespaces: Guide to handling XML namespaces properly
- Querying with XPath: How to use XPath expressions to query XML documents
- PHP Models to XML: Converting PHP objects to XML and vice versa
- Attribute-Based Mapping: Using PHP attributes to control XML serialization
- Cleaning Documents: Removing specific tags from XML documents
- File Operations: Loading and saving XML from/to files
- XML Validation: Validating XML documents against schemas
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