1: The $depth variable keeps track of how deep the child nodes are. eg. below, "title" and "content" would each be 1 deep, "subtitle" is 2 deep.
2: The spaces indent child nodes for better XML readability. eg.
HTML Code:
<item>
<title>one</title>
<subtitle>a</subtitle>
<content>blah, blah, blah</content>
</item>
instead of
HTML Code:
<item>
<title>one</title>
<subtitle>a</subtitle>
<content>blah, blah, blah</content>
</item>
3: $depth[$parser] is incremented in the startElement function and decremented in the endElement function. When the parser comes across a tag (<start> or </end>) the appropriate function changes the variable's value.
4: You could safely take out the spaces loop if you didn't mind losing the indentation (IMHO a few extra spaces for much easier readability is worth it, especially with more complex files). I don't know what would happen if you removed all the deptth stuff, but I have a feeling it wouldn't be good. I guess you could try it and see.
Bookmarks