XML_Statistics
[ class tree: XML_Statistics ] [ index: XML_Statistics ] [ all elements ]

Class: XML_Statistics

Source Location: /XML_Statistics-0.2.0/XML/Statistics.php

Class Overview

XML_Parser
   |
   --XML_Statistics

XML statistics class


Author(s):

Version:

  • 0.1

Methods


Inherited Variables

Inherited Methods


Class Details

[line 93]
XML statistics class

This class can be used to get statistic information about an XML document. It is able to extract to total number of tags, occurences of a specific tag, number of attributes, attributes in a specific tag, processing instruction, maximum nesting level and many more.

The class is able to analyze a file, URL or string.

  1.  require_once 'XML/Statistics.php';
  2.  $stat = new XML_Statistics();
  3.  $result $stat->analyzeFile('http://pear.php.net/rss.php');
  4.  if ($stat->isError($result)) {
  5.      die("Error: " $result->getMessage());
  6.  }
  7.  
  8.  echo "maximum nesting level: " $stat->getMaxDepth("<br />";
  9.  echo "occurences of item   : " $stat->countTag('item'"<br />";
  10.  echo "total tags           : " $stat->countTag("<br />";



[ Top ]


Method Detail

XML_Statistics (Constructor)   [line 178]

XML_Statistics XML_Statistics( [ $options = array()])

constructor

When instantiating a new object, you may specify an array containing options for the analysis. Currently only one option is possible:

  • ignoreWhitespace => true|false

  • Access: public

Parameters:

   $options   — 

[ Top ]

analyzeFile   [line 196]

boolean analyzeFile( $file, string $filename)

analyze a file or URL

After analyzing a file, use the count*() and get*() methods to retrieve the result of the analysis.


Parameters:

string   $filename   — 
   $file   — 

[ Top ]

analyzeString   [line 220]

boolean analyzeString( string $xml)

analyze an XML string

After analyzing a file, use the count*() and get*() methods to retrieve the result of the analysis.


Parameters:

string   $xml   —  the XML string to analyze

[ Top ]

apiVersion   [line 238]

string apiVersion( )

return API version
  • Return: API version
  • Access: public

[ Top ]

cdataHandler   [line 557]

void cdataHandler( object XML $parser, string $cdata)

Handler for character data
  • Access: protected

Parameters:

object XML   $parser   —  parser object
string   $cdata   —  CDATA

[ Top ]

countAttribute   [line 349]

integer countAttribute( [string $attribute = null], [string $tagname = null])

count the occurences of an attribute

Counts how often a certain attribute is used in the document. If no attribute is specified ot will count the total number of tags.

With the second parameter you may limit the search to a special tag.

  • Return: occurences of the attribute
  • Access: public

Parameters:

string   $attribute   —  if no attribute name is supplied, all attributes are counted
string   $tagname   —  this allows you to limit your search to a tag

[ Top ]

countDataChunks   [line 436]

integer countDataChunks( )

count the occurences of a data blocks

This is influenced by the 'ignoreWhitespace' option. Furthermore a new chunk is counted when the parser find a linebreak or internal entity.


[ Top ]

countExternalEntity   [line 414]

integer countExternalEntity( [string $name = null])

count the occurences of a external entitity

Counts how often a certain external is used in the document. If no name is specified ot will count the total number of external entities.

External entities have to be declared in your DTD:

 <!DOCTYPE page [
   <!ENTITY foo SYSTEM "foo.xml">
   <!ENTITY bar SYSTEM "bar.xml">
 ]>

  • Return: occurences of the entity
  • Access: public

Parameters:

string   $name   —  the name of the entity

[ Top ]

countPI   [line 384]

integer countPI( [string $target = null])

count the occurences of a processing instruction

Counts how often a certain processing instruction (e.g. <?PHP) is used in the document. The target is the 'language' of the processing instruction. You only need to specify the name, without the leading question mark. If no target is specified ot will count the total number of processing instructions.

  • Return: occurences of the processing instruction
  • Access: public

Parameters:

string   $target   —  if no tag name is supplied, all PIs are counted

[ Top ]

countTag   [line 302]

integer countTag( [string $tagname = null])

count the occurences of a tag

Counts how often a certain tag is used in the document. If no tagname is specified ot will count the total number of tags.


Parameters:

string   $tagname   —  if no tag name is supplied, all tags are counted

[ Top ]

countTagsInDepth   [line 326]

integer countTagsInDepth( integer $depth)

count the tags in a certain depth

Thru nesting a tag can be at a certain depth. The root tag is at depth zero. By counting the amount of tags in a depth you can count the number of recordsets in an XML document.


Parameters:

integer   $depth   —  tag depth (0 is root)

[ Top ]

endHandler   [line 544]

void endHandler( object XML $parser, string $element)

End element handler for XML parser
  • Access: protected

Parameters:

object XML   $parser   —  parser object
string   $element   — 

[ Top ]

entityrefHandler   [line 604]

void entityrefHandler( object XML $parser, string $open_entity_names, string $base, $system_id, $public_id)

Handler for external entities
  • Access: protected

Parameters:

object XML   $parser   —  parser object
string   $open_entity_names   —  target
string   $base   —  data
   $system_id   — 
   $public_id   — 

[ Top ]

getAttributeOccurences   [line 276]

array getAttributeOccurences( [ $tagname = null], string $tag)

get a list of attribute occurences

This will count the occurences of each attribute (by its unique name) in the document. It returns an associative array with the tag names in the keys and the number of occurences in the corresponding values.

If you specify a tagname this method will only count the occurences of attributes in this tag.


Parameters:

string   $tag   —  restrict to a tag
   $tagname   — 

[ Top ]

getCDataLength   [line 451]

integer getCDataLength( )

get the combined length of all CData sections

If you need to know how many chars you have between your tags, this is the method that gets it.


[ Top ]

getMaxDepth   [line 475]

integer getMaxDepth( )

get the maximum nesting level

This method will count how deep your document is nested.

 <root>
   <foo>
     <bar/>
   </foo>
 <root>

The nesting level of this document is 3.

  • Return: maximum nesting level
  • Access: public

[ Top ]

getTagOccurences   [line 254]

array getTagOccurences( )

get a list of tag occurences

This will count the occurences of each tag in the document. It returns an associative array with the tag names in the keys and the number of occurences in the corresponding values.


[ Top ]

piHandler   [line 582]

void piHandler( object XML $parser, string $target, string $data)

Handler for processing instructions
  • Access: protected

Parameters:

object XML   $parser   —  parser object
string   $target   —  target
string   $data   —  data

[ Top ]

startHandler   [line 489]

void startHandler( object $parser, string $element, array $attribs)

Start element handler for XML parser
  • Access: protected

Parameters:

object   $parser   —  XML parser object
string   $element   —  XML element
array   $attribs   —  attributes of XML tag

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:39:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.