Skip to content

Commit 5094e4e

Browse files
author
Rob Richards
committed
initial revision
requires PHP 5
1 parent be85c90 commit 5094e4e

12 files changed

+1178
-0
lines changed

ext/xmlreader/CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
XMLReader
2+
Rob Richards

ext/xmlreader/EXPERIMENTAL

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
this module is experimental,
2+
its functions may change their names
3+
so do not rely to much on them
4+
you have been warned!

ext/xmlreader/README

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
XMLReader represents a reader that provides non-cached,
2+
forward-only access to XML data. It is based upon the
3+
xmlTextReader api from libxml
4+
5+
This extension is designed to only work under PHP 5.

ext/xmlreader/TODO

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- Refactor internals once libxml 2.6.x is minimum requirement for PHP 5
2+
use new api for creating the xmlTextReaderPtr
3+
4+
- Add Custom Error Handling
5+
6+

ext/xmlreader/config.m4

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
dnl
2+
dnl $Id$
3+
dnl
4+
5+
PHP_ARG_WITH(xmlreader, for XMLReader support,
6+
[ --with-xmlreader Include XMLReader support.])
7+
8+
if test -z "$PHP_LIBXML_DIR"; then
9+
PHP_ARG_WITH(libxml-dir, libxml2 install dir,
10+
[ --with-libxml-dir=DIR XMLReader: libxml2 install prefix], no, no)
11+
fi
12+
13+
if test "$PHP_XMLREADER" != "no" && test "$PHP_LIBXML" != "no"; then
14+
15+
PHP_SETUP_LIBXML(XMLREADER_SHARED_LIBADD, [
16+
AC_DEFINE(HAVE_XMLREADER,1,[ ])
17+
PHP_NEW_EXTENSION(xmlreader, php_xmlreader.c, $ext_shared)
18+
PHP_SUBST(XMLREADER_SHARED_LIBADD)
19+
], [
20+
AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.])
21+
])
22+
fi

ext/xmlreader/config.w32

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
ARG_WITH("xmlreader", "XMLReader support", "yes");
5+
6+
if (PHP_XMLREADER == "yes" && PHP_LIBXML == "yes") {
7+
EXTENSION("xmlreader", "php_xmlreader.c");
8+
AC_DEFINE("HAVE_XMLREADER", 1, "XMLReader support");
9+
if (!PHP_XMLREADER_SHARED) {
10+
ADD_FLAG("CFLAGS_XMLREADER", "/D LIBXML_STATIC");
11+
}
12+
ADD_EXTENSION_DEP('xmlreader', 'libxml');
13+
}
14+

ext/xmlreader/examples/xmlreader.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<books>
2+
<book num="1">
3+
<title>The Grapes of Wrath</title>
4+
<author>John Steinbeck</author>
5+
</book>
6+
<book num="2">
7+
<title>The Pearl</title>
8+
<author>John Steinbeck</author>
9+
</book>
10+
</books>
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
$reader = new XMLReader();
3+
$reader->open('xmlreader.xml');
4+
while ($reader->read()) {
5+
if ($reader->nodeType != XMLREADER_END_ELEMENT) {
6+
print "Node Name: ".$reader->name."\n";
7+
print "Node Value: ".$reader->value."\n";
8+
print "Node Depth: ".$reader->depth."\n";
9+
if ($reader->nodeType==XMLREADER_ELEMENT && $reader->hasAttributes) {
10+
$attr = $reader->moveToFirstAttribute();
11+
while ($attr) {
12+
print " Attribute Name: ".$reader->name."\n";
13+
print " Attribute Value: ".$reader->value."\n";
14+
$attr = $reader->moveToNextAttribute();
15+
}
16+
}
17+
print "\n";
18+
}
19+
}
20+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
$xmlstring = '<books>
3+
<book num="1">
4+
<title>The Grapes of Wrath</title>
5+
<author>John Steinbeck</author>
6+
</book>
7+
<book num="2">
8+
<title>The Pearl</title>
9+
<author>John Steinbeck</author>
10+
</book>
11+
</books>';
12+
13+
$reader = new XMLReader();
14+
$reader->XML($xmlstring);
15+
while ($reader->read()) {
16+
if ($reader->nodeType != XMLREADER_END_ELEMENT) {
17+
print "Node Name: ".$reader->name."\n";
18+
print "Node Value: ".$reader->value."\n";
19+
print "Node Depth: ".$reader->depth."\n";
20+
if ($reader->nodeType==XMLREADER_ELEMENT && $reader->hasAttributes) {
21+
$attr = $reader->moveToFirstAttribute();
22+
while ($attr) {
23+
print " Attribute Name: ".$reader->name."\n";
24+
print " Attribute Value: ".$reader->value."\n";
25+
$attr = $reader->moveToNextAttribute();
26+
}
27+
}
28+
print "\n";
29+
}
30+
}
31+
?>

0 commit comments

Comments
 (0)