Skip to content
generated from php-lights/php

a nicer, lightweight wrapper around PHP's native XML API

License

Notifications You must be signed in to change notification settings

php-lights/php-xml

Repository files navigation

php-xml

License Docs CI Codecov

A PHP library that provides a nicer, lightweight wrapper around PHP's native XML API.

Install

composer install neoncitylights/xml

Requirements

  • PHP 8.3+
  • libxml (enabled by default in PHP)

Usage

<?php
use Neoncitylights\Xml\Encoding;
use Neoncitylights\Xml\XmlNativeParser;

// create a parser normally, or with an XML namespace
$parser = XmlNativeParser::new(Encoding::Utf8);
$parserNs = XmlNativeParser::newWithNamespace(Encoding::Utf8, ':');

// parse XML
$xmlFileStream = \fopen('example.xml');
while (($data = \fread($xmlFileStream, 16384))) {
    $parser->parse($data); // parse the current chunk
}
$parser->parseFinalize();
\fclose($xmlFileStream);

API Reference

  • Neoncitylights\Xml\Encoding - A string enum of the possible XML text encodings.
  • Neoncitylights\Xml\ErrorCode - An integer enum of the possible XML error codes, backed by core constants.
  • Neoncitylights\Xml\Option - An integer enum of the possible XML options that can be get or set, backed by core constants.
  • Neoncitylights\Xml\XmlNativeParser - A class that wraps around the native XmlParser class and built-in XML parsing functions.
  • Neoncitylights\Xml\XmlParseResult - A class that represents the values passed-by-reference from the xml_parse_into_struct() function.

License

This software is licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.