Skip to content

Commit 64588bc

Browse files
committed
Merge branch '2.x' of github.com:highwire/opensource-php-BetterDOMDocument into 2.x
2 parents ca2ff43 + 1acf759 commit 64588bc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
BetterDOMDocument is a handy PHP utility class for working with XML. It's a wrapper for PHP's built in DOMDocument that provides a bunch of nice shortcuts that
44
makes working with XML in PHP a breeze. It has great built-in support for namespaces, xpath, and CSS selectors.
55

6+
```
7+
composer require highwire/better-dom-document
8+
```
9+
610
```php
711
<?php
812

13+
use BetterDOMDocument\DOMDoc;
14+
915
// We can load a new BetterDOMDocument from either a string or a DOMNode object
10-
$dom = new BetterDOMDocument($xmlstring);
16+
$dom = new DOMDoc($xmlstring);
1117

1218
// It's easy to output the entire document as an array, which is sometimes easier to work with in PHP
1319
$array = $dom->getArray();
@@ -19,10 +25,10 @@ $node_list = $dom->xpath('//xpath/to/node', $optional_context_node);
1925
$dom_node = $dom->xpathSingle('//xpath/to/node');
2026

2127
// Swapping out DOMNodes is really easy
22-
$dom->replace($DomNode, $replacementNode);
28+
$dom->replace($dom_node, $replacementNode);
2329

2430
// Removing a node is easy
25-
$dom->remove($DomNode);
31+
$dom->remove($dom_node);
2632

2733
// Most places where you want to pass a DOMNode or element, you can just pass an xpath instead
2834
$dom->remove('//xpath/to/element/to/remove');
@@ -34,7 +40,7 @@ $dom->replace('//xpath/to/replace', '<xml>You can pass a string, a DOMNode, or a
3440
$xml = $dom->out();
3541

3642
// Or just output a single DOMNode
37-
$xml = $dom->out($DOMNode);
43+
$xml = $dom->out($dom_node);
3844

3945

4046
// Working with namespaced documents is made really easy
@@ -51,7 +57,7 @@ $xml = '
5157

5258
// If your document (like the one above) has a default namespace, you should declare
5359
// it's prefix as the second value when constructing a new BetterDOMDocument
54-
$dom = new BetterDOMDocument($xml, 'atom'); // We register the 'atom' prefix against the default namespace
60+
$dom = new DOMDoc($xml, 'atom'); // We register the 'atom' prefix against the default namespace
5561

5662
// Now we can do mixed namespace queries!
5763
$surname = $dom->querySingle('//atom:author/nlm:name/nlm:surname')->nodeValue;

0 commit comments

Comments
 (0)