-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.php
58 lines (41 loc) · 1.32 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
use ByJG\XmlUtil\XmlDocument;
require "vendor/autoload.php";
$xml = new XmlDocument('<root />');
$myNode = $xml->appendChild('mynode');
$xml->appendChild('subnode', 'text');
$xml->appendChild('subnode', 'more text');
$otherNode = $xml->appendChild('othersubnode', 'other text');
$otherNode->addAttribute('attr', 'value');
echo $xml->toString(true);
print_r($xml->toArray());
$node = $xml->selectSingleNode('//subnode');
echo $node->DOMNode()->nodeValue . "\n";
$node = $myNode->selectSingleNode('//subnode');
echo $node->DOMNode()->nodeValue . "\n";
$nodeList = $xml->selectNodes('//subnode');
foreach ($nodeList as $node)
{
echo $node->nodeName;
}
echo "\n";
$nodeList = $myNode->selectNodes('//subnode');
foreach ($nodeList as $node)
{
echo $node->nodeName;
}
echo "\n";
$xml->addNamespace('my', 'http://www.example.com/mytest/');
echo $xml->toString(true) . "\n";
$xml->appendChild('nodens', 'teste', 'http://www.example.com/mytest/');
$xml->appendChild('my:othernodens', 'teste');
echo $xml->toString(true) . "\n";
$nodeList = $xml->selectNodes('//my:othernodens', [ 'my' => 'http://www.example.com/mytest/' ] );
foreach ($nodeList as $node)
{
echo 'A' . $node->nodeName;
}
//$str = '<?xml version="1.0" encoding="utf-8"'
// . '<root xmlns:my="http://www.example.com/mytest/">'
// . ' '
// . '</root>';