I'm working on documenting the XMLReader and XMLWriter classes. Is there
someone on the list that can answer some questions about the details of
how XMLReader works?
Thanks.
-John
John Stokes jstokes@heartofthefyre.us schrieb:
I'm working on documenting the XMLReader and XMLWriter classes. Is there
someone on the list that can answer some questions about the details of
how XMLReader works?
Please don't ask to ask. Sent a mail to this list or to the php.doc
mailinglist and just ask your question.
Thank you
ps.: yes there will be people that can answer questions regarding those
two classes
Well, fine then.
I'm trying to understand the mechanics behind XMLReader::next() and
XMLReader::read()
Given an XML file like this:
$library = '
<?xml version="1.0"?>
<library>
<book>
<title>Of Mice and Men</title>
</book>
<book>
<title>A Tale of Two Cities</title>
</book>
</library>';
$XMLdoc = XMLReader::XML($library);
It seems to me that the XMLReader object essentially functions as a pointer.
QUESTION 1
I'm guessing that calling $XMLdoc->next(); moves the pointer like this.
POINTER--> <library>
<book>
...
However, a call to readOuterXML(), readInnerXML(), etc. results in
nothing being printed.
Another $XMLdoc->next(); call results in
...
</book>
POINTER--></library>
And again, a call to read...XML() results in nothing being printed. The
second case makes sense, because you're at the end of the document. I
don't understand why the first call returns nothing.
QUESTION 2
A similar scenario using XMLReader::read(). If I were to do successive
calls to $XMLdoc->read(); and $XMLdoc->readOuterXML() I get:
-
POINTER--><library>
<book>
...
Prints the whole document. -
<library>POINTER-->(empty text node)
<book>
...
Prints nothing, as expected. - <library> POINTER--><book> <title>Of Mice and Men</title> ...
SHOULD print the whole book node. It doesn't.
- <library> <book>POINTER-->(empty text node) <title>Of Mice and Men</title> ...
Prints nothing, as expected.
- <library> <book> POINTER--><title>Of Mice and Men</title> ...
Prints <title>Of Mice and Men</title>
- <library> <book> <title>POINTER-->Of Mice and Men</title> ...
Prints Of Mice and Men
Why doesn't iteration 3 print the entire book node?
QUESTION 2a
Using the same scenario as above, does the read() actually read in the
entire document on iteration 1, or does it wait for a call to
readOuterXML(),readInnerXML(), etc? If it actually reads the entire
document, doesn't that defeat the purpose of a pull parser?
QUESTION 3
Starting with iteration 3 above, if I assume that it DID print the whole
book node, a call to $XMLdoc->next() should do this:
<library>
<book>
<title>Of Mice and Men</title>
</book>
POINTER--><book>
<title>A Tale of Two Cities</title>
...
Now a call to readOuterXML() SHOULD print the entire 2nd book node.
Instead it prints nothing. Why?
Thanks in advance for the help.
-John
John Stokes jstokes@heartofthefyre.us schrieb:
I'm working on documenting the XMLReader and XMLWriter classes. Is there
someone on the list that can answer some questions about the details of
how XMLReader works?
Please don't ask to ask. Sent a mail to this list or to the php.doc
mailinglist and just ask your question.Thank you
ps.: yes there will be people that can answer questions regarding those
two classes
UPDATE: I figured out number 2. Maybe I had an extra text node in there,
but now it's working.
Can someone help with the others?
-John
Well, fine then.
I'm trying to understand the mechanics behind XMLReader::next() and
XMLReader::read()Given an XML file like this:
$library = '
<?xml version="1.0"?>
<library>
<book>
<title>Of Mice and Men</title>
</book>
<book>
<title>A Tale of Two Cities</title>
</book>
</library>';
$XMLdoc = XMLReader::XML($library);It seems to me that the XMLReader object essentially functions as a
pointer.QUESTION 1
I'm guessing that calling $XMLdoc->next(); moves the pointer like this.POINTER--> <library>
<book>
...However, a call to readOuterXML(), readInnerXML(), etc. results in
nothing being printed.Another $XMLdoc->next(); call results in
...
</book>
POINTER--></library>And again, a call to read...XML() results in nothing being printed.
The second case makes sense, because you're at the end of the
document. I don't understand why the first call returns nothing.QUESTION 2
A similar scenario using XMLReader::read(). If I were to do successive
calls to $XMLdoc->read(); and $XMLdoc->readOuterXML() I get:
POINTER--><library>
<book>
...
Prints the whole document.<library>POINTER-->(empty text node)
<book>
...
Prints nothing, as expected.- <library> POINTER--><book> <title>Of Mice and Men</title> ...
SHOULD print the whole book node. It doesn't.
- <library> <book>POINTER-->(empty text node) <title>Of Mice and Men</title> ...
Prints nothing, as expected.
- <library> <book> POINTER--><title>Of Mice and Men</title> ...
Prints <title>Of Mice and Men</title>
- <library> <book> <title>POINTER-->Of Mice and Men</title> ...
Prints Of Mice and Men
Why doesn't iteration 3 print the entire book node?
QUESTION 2a
Using the same scenario as above, does the read() actually read in the
entire document on iteration 1, or does it wait for a call to
readOuterXML(),readInnerXML(), etc? If it actually reads the entire
document, doesn't that defeat the purpose of a pull parser?QUESTION 3
Starting with iteration 3 above, if I assume that it DID print the
whole book node, a call to $XMLdoc->next() should do this:
<library>
<book>
<title>Of Mice and Men</title>
</book>
POINTER--><book>
<title>A Tale of Two Cities</title>
...Now a call to readOuterXML() SHOULD print the entire 2nd book node.
Instead it prints nothing. Why?Thanks in advance for the help.
-John
John Stokes jstokes@heartofthefyre.us schrieb:
I'm working on documenting the XMLReader and XMLWriter classes. Is
there
someone on the list that can answer some questions about the details of
how XMLReader works?
Please don't ask to ask. Sent a mail to this list or to the php.doc
mailinglist and just ask your question.Thank you
ps.: yes there will be people that can answer questions regarding those
two classes