getNodeFrom() public method

Tries to retrieve the next node or returns false
public getNodeFrom ( Prewk\XmlStringStreamer\StreamInterface $stream ) : string | boolean
$stream Prewk\XmlStringStreamer\StreamInterface The stream to use
return string | boolean The next xml node or false if one could not be retrieved
コード例 #1
0
    public function test_multiple_roots()
    {
        $node1 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
            </child>
eot;
        $node2 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>2</index>
            </child>
eot;
        $node3 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>3</index>
            </child>
eot;
        $node4 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>3</index>
            </child>
eot;
        $xml = <<<eot
            <?xml version="1.0"?>
            <root-a>
                {$node1}
                {$node2}
            </root-a>
            <root-b>
                {$node3}
                {$node4}
            </root-b>
eot;
        $stream = $this->getStreamMock($xml, 50);
        $parser = new UniqueNode(array("uniqueNode" => "child"));
        $this->assertEquals(trim($node1), trim($parser->getNodeFrom($stream)), "Node 1 should be obtained on the first getNodeFrom from root-a");
        $this->assertEquals(trim($node2), trim($parser->getNodeFrom($stream)), "Node 2 should be obtained on the second getNodeFrom from root-a");
        $this->assertEquals(trim($node3), trim($parser->getNodeFrom($stream)), "Node 3 should be obtained on the third getNodeFrom from root-b");
        $this->assertEquals(trim($node4), trim($parser->getNodeFrom($stream)), "Node 4 should be obtained on the third getNodeFrom from root-b");
        $this->assertFalse(false, "When no nodes are left, false should be returned");
    }
コード例 #2
0
    public function test_sibling_nodes()
    {
        $node1 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
            </child>
eot;
        $node3 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
                {$node1}
                {$node1}
            </child>
eot;
        $node2 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
                {$node3}
                {$node1}
            </child>
eot;
        $xml = <<<eot
            <?xml version="1.0"?>
            <root>
                {$node2}
            </root>
eot;
        $stream = $this->getStreamMock($xml, 50);
        $parser = new UniqueNode(array("uniqueNode" => "child", "ignoreNestedNodes" => true));
        $node = $parser->getNodeFrom($stream);
        $this->assertEquals(trim($node2), trim($node), "Nested siblings should be ignored");
    }