PHP DOM function read line number from input file
I have a program that reads an XML file using DOM functions:
$doc = new DOMDocument('1.0');
$doc->load("myFile.xml");
As I traverse the nodes in this document, is there a way to determine which line in the input file a node was defined on?
For instance:
1: <!-- myFile.xml -->
2: <foobar>
3: <foo>FOO</foo>
4: <bar>BAR</bar>
5: </foobar>
and PHP:
$xp = new DOMXPath($doc);
$bars = $xp->query("//bar");
$myBar = $bars[0];
echo "The first <bar> element is on line " . performMagicHere(); // 4
+1
a source to share
2 answers
You cannot do this with the PHP DOM class. DOM Level 3 added support for this , but we don't have DOM Level 3 support in PHP yet.
+1
a source to share