This method appears to follow these rules:
- if $localName names a sibling node, the cursor is moved to that node;
- if $localName names an ancestor node, the cursor is moved to the end of that node;
- if $localName names a node that is a sibling of any of the current node's ancestors, the cursor is moved to that node;
- otherwise the cursor is moved outside the document.
Note especially that this method never moves the cursor to child nodes.
For example, given this XML document
<?xml version="1.0" encoding="UTF-8"?>
<root id="root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<aaa id="1">
<bbb id="1.1"></bbb>
<bbb id="1.2"></bbb>
</aaa>
<ccc id="2" />
<aaa id="3">
<ddd id="3.1">
<aaa id="3.1.1"></aaa>
</ddd>
<aaa id="3.2"></aaa>
</aaa>
<aaa id="4">
<eee id="4.1"></eee>
</aaa>
</root>
going from <root id="root"> to "bbb" places the cursor outside the document;
going from <aaa id="1"> to "bbb" places the cursor outside the document;
going from <aaa id="1"> to "aaa" places the cursor on <aaa id="3">;
going from <bbb id="1.1"> to "bbb" places the cursor on <bbb id="1.2">;
going from <bbb id="1.2"> to "bbb" places the cursor outside the document;
going from <bbb id="1.1"> to "ddd" places the cursor outside the document;
going from <bbb id="1.1"> to "aaa" places the cursor on </aaa>;
going from <bbb id="1.1"> to "ccc" places the cursor on <ccc id="2">;
going from <bbb id="1.1"> to "nonsuch" places the cursor outside the document;
going from <bbb id="1.1"> to "root" places the cursor on </root>;
going from <ddd id="3.1"> to "aaa" places the cursor on <aaa id="3.2">;
going from <ddd id="3.1"> to "eee" places the cursor outside the document;
Try it yourself:
<?php
$document = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<root id="root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<aaa id="1">
<bbb id="1.1"></bbb>
<bbb id="1.2"></bbb>
</aaa>
<ccc id="2" />
<aaa id="3">
<ddd id="3.1">
<aaa id="3.1.1"></aaa>
</ddd>
<aaa id="3.2"></aaa>
</aaa>
<aaa id="4">
<eee id="4.1"></eee>
</aaa>
</root>
XML;
$filename = "/tmp/xmlreader.php.xml";
file_put_contents($filename, $document);
echo "given this XML document\n\n$document\n\n";
showNext("root", "bbb");
showNext("1", "bbb");
showNext("1", "aaa");
showNext("1.1", "bbb");
showNext("1.2", "bbb");
showNext("1.1", "ddd");
showNext("1.1", "aaa");
showNext("1.1", "ccc");
showNext("1.1", "nonsuch");
showNext("1.1", "root");
showNext("3.1", "aaa");
showNext("3.1", "eee");
function showNext($from, $to) {
global $filename;
$xml = new \XmlReader();
$xml->open("file://$filename");
while ($xml->read()) {
if ($xml->nodeType === \XmlReader::ELEMENT) {
if ($xml->getAttribute("id") == $from) {
echo "going from <$xml->name id=\"$from\">";
break;
}
}
}
$xml->next($to);
$destination = "";
if($xml->nodeType === \XmlReader::NONE) {
if(!$xml->read()) {
$destination = "outside the document";
}
}
if(!$destination) {
if ($xml->nodeType === \XmlReader::END_ELEMENT) {
$destination = "on </$xml->name>";
} else if ($xml->nodeType === \XmlReader::ELEMENT) {
$destination = "on <$xml->name id=\"" . $xml->getAttribute("id") . "\">";
}
}
echo " to \"$to\" places the cursor $destination;\n";
$xml->close();
}
?>
PHP.mk документација
XMLReader::next
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
xmlreader.next.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
xmlreader.next.php
XMLReader::next
Референца за `xmlreader.next.php` со подобрена типографија и навигација.
XMLReader::next
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
XMLReader::next — Помести го курсорот на следниот јазол прескокнувајќи ги сите поддрвја
= NULL
Ја поставува положбата на курсорот на следниот јазол прескокнувајќи ги сите поддрвја. Ако не постои таков јазол, курсорот се поместува на крајот од документот.
Параметри
name-
Името на следниот јазол на кој треба да се премести.
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.0 |
name сега е null.
|
Види Исто така
- XMLReader::moveToNextAttribute() - Позиционирај го курсорот на следниот атрибут
- XMLReader::moveToElement() - Позиционирај го курсорот на родителскиот елемент на тековниот атрибут
- XMLReader::moveToAttribute() - Помести го курсорот на именувана атрибут
Белешки од корисници 3 белешки
ppp dot BOTSNEEDNOTAPPLY at salesfloor dot net ¶
пред 10 години
Тивок шум ¶
пред 6 години
next() without parameters will bring you to the next sibling node on the same depth as the depth where the current cursor is.
Examples:
1. If you are on an opening ELEMENT node next() will bring you to the new line node next to the closing tag of that element (i.e. if you have each tag in separate line) or it will bring you to the opening tag of next node on the same depth.
2. If you are on a TEXT node next() will bring you to the opening tag if there is one next to it.
If there are no more nodes on the given depth next() will bring you to the closing tag (END_ELEMENT) of the wrapping parent.
gholson19 at gmail dot com ¶
пред 10 години
To skip over deletion nodes in the xml extracted from a word document, do something like this:
if ($paragraph->nodeType == XMLREADER::ELEMENT && $paragraph->name === 'w:del'){$paragraph->next();}