All Projects → ThomasWeinert → Fluentdom

ThomasWeinert / Fluentdom

Licence: mit
A fluent api for working with XML in PHP

Projects that are alternatives of or similar to Fluentdom

Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (+492.97%)
Mutual labels:  dom, xml, xpath
Jquery Xpath
jQuery XPath plugin (with full XPath 2.0 language support)
Stars: ✭ 173 (-47.09%)
Mutual labels:  xml, xpath, dom
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+2708.56%)
Mutual labels:  dom, xml, xpath
Pugixml
Light-weight, simple and fast XML parser for C++ with XPath support
Stars: ✭ 2,809 (+759.02%)
Mutual labels:  xml, xpath, dom
Xml
XML without worries
Stars: ✭ 35 (-89.3%)
Mutual labels:  xml, xpath, dom
Amplesdk
Ample SDK - JavaScript UI Framework
Stars: ✭ 169 (-48.32%)
Mutual labels:  xml, dom
Svgdom
Straightforward DOM implementation to make SVG.js run headless on Node.js
Stars: ✭ 154 (-52.91%)
Mutual labels:  xml, dom
Xmlquery
xmlquery is Golang XPath package for XML query.
Stars: ✭ 209 (-36.09%)
Mutual labels:  xml, xpath
Exist
eXist Native XML Database and Application Platform
Stars: ✭ 294 (-10.09%)
Mutual labels:  xml, xpath
Phpstamp
The XSL-way templating library for MS Office Word DOCX documents.
Stars: ✭ 150 (-54.13%)
Mutual labels:  xml, dom
Ono
A sensible way to deal with XML & HTML for iOS & macOS
Stars: ✭ 2,599 (+694.8%)
Mutual labels:  xml, xpath
xpath2.js
xpath.js - Open source XPath 2.0 implementation in JavaScript (DOM agnostic)
Stars: ✭ 74 (-77.37%)
Mutual labels:  dom, xpath
Preact Markup
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!
Stars: ✭ 167 (-48.93%)
Mutual labels:  xml, dom
Xquery
Extract data or evaluate value from HTML/XML documents using XPath
Stars: ✭ 155 (-52.6%)
Mutual labels:  xml, xpath
fox
A Fortran XML library
Stars: ✭ 51 (-84.4%)
Mutual labels:  dom, xml
Meeseeks
An Elixir library for parsing and extracting data from HTML and XML with CSS or XPath selectors.
Stars: ✭ 252 (-22.94%)
Mutual labels:  xml, xpath
XPath2.Net
Lightweight XPath2 for .NET
Stars: ✭ 26 (-92.05%)
Mutual labels:  xml, xpath
XPathTools
A Visual Studio Extension which can run any XPath and XPath function; navigates through results at the click of a button. Can show and copy any XPath incl. XML namespaces, avoiding XML namespace induced headaches. Keeps track of the current XPath via the statusbar.
Stars: ✭ 40 (-87.77%)
Mutual labels:  xml, xpath
xmlresolver
The xmlresolver project provides an advanced implementation of the SAX EntityResolver (and extended EntityResolver2), the Transformer URIResolver, the DOM LSResourceResolver, the StAX XMLResolver, and a new NamespaceResolver. It uses the OASIS XML Catalogs V1.1 Standard to provide a mapping from external identifiers and URIs to local resources.
Stars: ✭ 31 (-90.52%)
Mutual labels:  dom, xml
Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (-65.75%)
Mutual labels:  xml, xpath

FluentDOM

CI

[comment]: <> ([![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/fluentdom/fluentdom.svg)](https://scrutinizer-ci.com/g/FluentDOM/FluentDOM/?branch=master&#41;) [comment]: <> ([![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/fluentdom/fluentdom.svg)](https://scrutinizer-ci.com/g/FluentDOM/FluentDOM/?branch=master&#41;)

License Total Downloads Latest Stable Version Latest Unstable Version

Copyright: 2009-2018 FluentDOM Contributors
License: The MIT License

FluentDOM provides extended XML handling classes for PHPs DOM, XMLReader and XMLWriter. Additionally, it contains a easy to use jQuery like, fluent interface for DOM.

Here are loaders and serializers for different formats like JSON, YAML, JsonML and others. More (like HTML5) can be installed as additional packages.

FluentDOM is a test driven project. We write tests before and during the development. You will find the PHPUnit tests in the tests/ subdirectory.

Table Of Contents

  • Examples
  • Support
  • Requirements
  • Packagist
  • Usage
  • Backwards Compatibility Breaks

Examples

Many examples can be found in the examples/ subdirectory. Here are some for an initial impression:

Read All Links in a HTML File

$document = FluentDOM::load(
  $htmlFile,
  'text/html',
  [FluentDOM\Loader\Options::ALLOW_FILE => TRUE]
);
foreach ($document('//a[@href]') as $a) {
  $links[] = [
    'caption' => (string)$a,
    'href' => $a['href']
  ];
}
var_dump($links);

Create a Select From an Array

$_ = FluentDOM::create();
$_->formatOutput = TRUE;
echo $_(
  'select',
  ['name' => 'example'],
  $_->each(
    ['One', 'Two', 'Three'],
    function($text, $index) use ($_) {
      return $_('option', ['value' => $index], $text);
    }
  )
)->document->saveHTML();

Read Large XML Files (FluentDOM 6.2)

$reader = new FluentDOM\XMLReader();
$reader->open('sitemap.xml');
$reader->registerNamespace('s', 'http://www.sitemaps.org/schemas/sitemap/0.9');

foreach (new FluentDOM\XMLReader\SiblingIterator($reader, 's:url') as $url) {
  /** @var FluentDOM\DOM\Element $url */
  var_dump(
    [
      'location' => $url('string(s:loc)'),
      'updated' => $url('string(s:lastmod)')
    ]
  );
}

Support

The wiki provides information and usage examples.

If you find a bug or have a feature request please report it in the issue tracker.

You can check out the Gitter chat, too.

Be ware that the release packages (downloads) do not include the examples or tests. They are not needed to use the library. If you clone the repository, they will be included.

Security Issues

If you find a bug that has security implications, you can send an email directly to [email protected].

Requirements

PHP

  • PHP >= 7.0
  • ext/dom
  • Optional
    • ext/xmlreader
    • ext/xmlwriter

FluentDOM needs at least PHP 7.0 and the DOM extension. For some features additional extensions might be needed, like ext/json to load JSON strings.

To use the extended XMLReader/XMLWriter you will need the respective PHP extensions, of course.

HHVM

FluentDOM 5.2 and later requires HHVM 3.5.

FluentDOM 4.0 to 5.1 work with HHVM 3.3 but it was limited. If you like to use HHVM it is strongly suggest to use newer releases.

FluentDOM 7.0 and later has not support for HHVM any more.

Packagist

FluentDOM is available on Packagist.org, just add the dependency to your composer.json.

{
  "require": {
    "fluentdom/fluentdom": "^7.0"
  }
}

Usage

The following examples load the sample.xml file, look for tags <h1> with the attribute "id" that has the value "title", set the content of these tags to "Hello World" and output the manipulated document.

Extended DOM (FluentDOM >= 5.2)

Using the FluentDOM\Document class:

$fd = FluentDOM::load('sample.xml');
foreach ($fd('//h1[@id = "title"]') as $node) {
  $node->nodeValue = 'Hello World!';
}

echo $fd->saveXml();

jQuery Style API

Using the FluentDOM\Query class:

echo FluentDOM('sample.xml')
  ->find('//h1[@id = "title"]')
  ->text('Hello World!');

CSS Selectors

If you install a CSS selector to Xpath translation library into a project, you can use the FluentDOM::QueryCss() function. It returns a FluentDOM\Query instance supporting CSS 3 selectors.

$fd = FluentDOM::QueryCss('sample.xml')
  ->find('h1#title')
  ->text('Hello World!');

Read more about it in the Wiki

Creating XML

New features in FluentDOM make it easy to create XML, even XML with namespaces. Basically you can register XML namespaces on the document and methods without direct namespace support (like createElement()) will resolve the namespace and call the namespace aware variant (like createElementNS()).

Check the Wiki for an example.

Backwards Compatibility Breaks

From 6.2 to 7.0

The minimum required PHP version now is 7.0. HHVM is not supported any more. Scalar type hints and return types were added.

Moved the extended DOM classes into the FluentDOM\DOM namespace. (FluentDOM\Document -> FluentDOM\DOM\Document). FluentDOM\Nodes\Creator was moved to FluentDOM\Creator. Several internal classes were moved into a FluentDOM\Utiltity namespace.

FluentDOM\Query::get() now return a DOMNodeis the position was provided, not an array any more.

FluentDOM\DOM\Element::find() was removed, use FluentDOM($element)->find().

Previous BC breaks are documented in the Wiki.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].