topical media & game development

talk show tell print

server-php-xml-class-xml-check-class-xml-check.htm / htm



  <html>
  <head>
  <title>XML Check (class_xml_check.php)</title>
  <link rel="stylesheet" href="main.css" type="text/css">
  </head>
  
  <body>
  <div align="center">
  <table border="0" width="80%" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#aaaaee" class="text" align="center"><a href="http://phpxmlclasses.sourceforge.net/">PHP XML Classes</a></td>
  </tr>
  </table>
  <table border="0" width="80%" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#aaaaee" class="textblbl" align="center">XML Check (class_xml_check.php)</td>
  </tr>
  </table>
  <br/>
  <table border="0" width="80%">
  <tr>
    <td bgcolor="#eeeeff" class="text">Description: This class can validate if a document is well-formed XML, it
    uses a fast parsing strategy reporting error message, error line and column number if an error is found.<br/><br/>
    If the document is well-formed the class reports statistics about the document such as size, number of elements,
    number of attributes, number of text sections and size of text sections.<br/><br/>
    Documents can be checked from a PHP string, a path or a URL.
    </td>
  </tr>
  </table>
  <br/>
  <table border="0" bgcolor="ddddff" width="80%">
  <tr>
    <td valign="top" class="text" width="50%"><b>NEWS:</b>
    <ul>
      <li> 07-05-2002 First version of this class released.
    </ul>
    </td>
    <td valign="top" width="50%" class="text">
       This class code as well as documentation are hosted at <a href="http://www.sourceforge.net">SourceForge</a>
       please visit our <a href="http://www.sourceforge.net/projects/phpxmlclasses/">SourceForge page</a> for releases, documentation, bug-tracking, support
       forums and mailing lists.
    </td>
  </tr>
  </table>
  <br/>
  <table border="0" width="80%" cellpadding="0" cellspacing="0">
  <tr>
    <td class="textbl" bgcolor="aaaaee" width="50%">Resources</td>
    <td class="textbl" bgcolor="aaaaee" width="50%">Requirements</td>
  </tr>
  </table>
  <table border="1" width="80%" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" bgcolor="eeeeff" class="text" width="50%">
    <ul>
      <li><a class="textbl" href="http://www.sourceforge.net/projects/phpxmlclasses">Downloads</a>
      <li><a class="textbl" href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpxmlclasses/rdql_db/">Browse CVS</a>
      <li><a class="textbl" href="http://sourceforge.net/tracker/?atid=470965&group_id=53613&func=browse">Report Bugs</a>
    </ul>
    </td>
    <td valign="top" bgcolor="eeeeff" class="text" width="50%">
    <ul>
      <li>PHP 4.0.5+
    </ul>
    </td>
  </tr>
  </table>
  <br/>
  <table border="0" width="80%" cellpadding="0" cellspacing="0">
  <tr>
    <td class="textbl" bgcolor="aaaaee" width="50%">Features</td>
    <td class="textbl" bgcolor="aaaaee" width="50%">To-dos</td>
  </tr>
  </table>
  <table border="1" width="80%" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" bgcolor="eeeeff" class="text" width="50%">
    <ul>
      <li>Documents can be checked from URLs, files or PHP strings.
      <li>Huge documents can be checked without cosuming excesive server resources.
    </ul>
    </td>
    <td valign="top" bgcolor="ddddff" class="text" width="50%">
    <ul>
      <li>If you have a suggestion please let me know it.
    </ul>
    </td>
    
  </tr>
  </table>
  <br/>
  <table border="0" bgcolor="ddddff" width="80%">
  <tr>
  <!--
    <td valign="top" class="text" width="50%"><b>To-do/future releases:</b>
    <ul>
      <li>Class 
      <li>Class 
      <li>Class 
    </ul>
    </td> -->
    <td valign="top" width="100%" class="text">
       Contact: Luis Argerich (<a href="mailto:lrargerich@yahoo.com">;lrargerich@yahoo.com</a>)
    </td>
  </tr>
  </table>
  <br/>
  <table border="0" bgcolor="ddddff" width="80%">
  <tr>
  <!--
    <td valign="top" class="text" width="50%"><b>To-do/future releases:</b>
    <ul>
      <li>Class 
      <li>Class 
      <li>Class 
    </ul>
    </td> -->
    <td valign="top" width="100%" class="text">
      <b>Detailed description and usage:</b>
  <br/><br/>
  This class is very easy to use, this is a very simple example:
  <pre>
  check = new XML_check();
  if(check->check_string(myxml)) {
    print("XML is well-formed");
    print("Elements      : ".check->get_xml_elements());
    print("Attributes    : ".check->get_xml_attributes());
    print("Size          : ".check->get_xml_size());
    print("Text sections : ".check->get_xml_text_sections());
    print("Text size     : ".check->get_xml_text_size());
  } else {
    print("XML is not well-formed<br/>");
    print(check->get_full_error());
  }
  </pre>
  You can use check url instead, for example:
  <pre>
  if(check->check_url("http://www.w3.org/")) {
    print("XML is well-formed<br/>");
    print("Elements      : ".check->get_xml_elements()."<br/>");
    print("Attributes    : ".check->get_xml_attributes()."<br/>");
    print("Size          : ".check->get_xml_size()."<br/>");
    print("Text sections : ".check->get_xml_text_sections()."<br/>");
    print("Text size     : ".check->get_xml_text_size()."<br/>");
  } else {
    print("XML is not well-formed<br/>");
    print(check->get_full_error());
  }
  </pre>
  So we know the W3C home page is well formed XHTML :-)
  </div>
  <h3>Documentation</h3>
  <h2>Classes</h2>
  <ul>
    <li><a href="#class39">XML_check</a></li>
  </ul>
  
  <a name="class39"></a>
  <h3>XML_check</h3>
  Extends: None
Description: The class can be used to check if a URL, a file or a string is well formed XML, if not you can get an error message, line number and column number. If the source is well-formed you can get statistics about the XML file such as number of elements, attributes, text sections, size and size of text_sections.
<br> <!-- METHOD SUMMARY --> <A NAME="pDomNode_method_summary"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method1">get_error_code</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns an error code if the source is not well formed</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method2">get_error_line</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the line number where an error was detected</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method3">get_error_column</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the column number where the parser failed</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method4">get_error_msg</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This method returns the error message if the source is not well formed</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method5">get_full_error</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a complete error message if the source is not well formed</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method6">get_xml_size</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns XML document size</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method7">get_xml_elements</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the number of elements in the document</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method8">get_xml_attributes</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the number of attributes in the document</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method9">get_xml_text_sections</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the number of character data sections in the document</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;integer</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method10">get_xml_text_size</A></B>()</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the size of the text sections in the document</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;boolean</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method11">check_url</A></B>(string url)</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checks if a URL is well formed XML</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>&nbsp;boolean</CODE></FONT></TD> <TD><CODE><B><A HREF="#class39method12">check_string</A></B>(string url)</CODE> <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checks if a PHP string is well formed XML</TD> </TR> <!-- A ROW --> </TABLE> &nbsp; <P> <!-- METHOD SUMMARY --> <!-- ============ METHOD DETAIL ========== --> <A NAME="method_detail"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=1><FONT SIZE="+2"> <B>Method Detail</B></FONT></TD> </TR> </TABLE> <!-- method --> <A NAME="class39method1"><!-- --></A> <H3>get_error_code</H3> <PRE> integer <B>get_error_code</B>()</PRE> <DL> <DD>This method returns an error code number if the source wasn't well formed<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>An error number<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method2"><!-- --></A> <H3>get_error_line</H3> <PRE> integer <B>get_error_line</B>()</PRE> <DL> <DD>If the data source is not well formed this method can be used to get the line number where the parser failed.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The line number where the parser failed.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method3"><!-- --></A> <H3>get_error_column</H3> <PRE> integer <B>get_error_column</B>()</PRE> <DL> <DD>If the source being checked is not well formed this method can be used to return the column number where the error was detected<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The column number where the parser failed<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method4"><!-- --></A> <H3>get_error_msg</H3> <PRE> string <B>get_error_msg</B>()</PRE> <DL> <DD>If the data source being validated is not well formed this method can be used to return an error message describing the error.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The error message if the parser fails.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method5"><!-- --></A> <H3>get_full_error</H3> <PRE> string <B>get_full_error</B>()</PRE> <DL> <DD>This method returns an error message describing the error, the line number and column number. It can be used to provide a descriptive message to the user if needed.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>An string containing the error message, the line number and column number.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method6"><!-- --></A> <H3>get_xml_size</H3> <PRE> integer <B>get_xml_size</B>()</PRE> <DL> <DD>If the source is well formed this method returns the document size in bytes.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The document size in bytes.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method7"><!-- --></A> <H3>get_xml_elements</H3> <PRE> integer <B>get_xml_elements</B>()</PRE> <DL> <DD>If the document was well formed this method returns the number of XML elements in the document<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The number of elements in the document<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method8"><!-- --></A> <H3>get_xml_attributes</H3> <PRE> integer <B>get_xml_attributes</B>()</PRE> <DL> <DD>If the source was well formed this method returns the number of XML attributes seen in the document<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The number of XML attributes in the document<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method9"><!-- --></A> <H3>get_xml_text_sections</H3> <PRE> integer <B>get_xml_text_sections</B>()</PRE> <DL> <DD>If the source is well formed this method returns the number of character data sections reported by the parser.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The number of character data sections in the document<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method10"><!-- --></A> <H3>get_xml_text_size</H3> <PRE> integer <B>get_xml_text_size</B>()</PRE> <DL> <DD>If the source is well formed this method returns the size of all the character data sections found in the document<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>The size of all the character data sections in the document<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method11"><!-- --></A> <H3>check_url</H3> <PRE> boolean <B>check_url</B>(string url)</PRE> <DL> <DD>This method can be used to check if a document located at a given URL is well formed XML and collect statistics about the document.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> url - The URL to be checked<br><DT><B>Returns:</B><DD>True if the document is well formed (stats can be obtained calling adhoc methds) false if the document is not well formed (see methods to get error description, line and column number)<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class39method12"><!-- --></A> <H3>check_string</H3> <PRE> boolean <B>check_string</B>(string url)</PRE> <DL> <DD>This method can be used to check if the content of a PHP string is well formed XML, if so statistics can be obtained, if not you can get the error description, column number and column.<DD>&nbsp; <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>True if the document is well formed (stats can be obtained calling adhoc methds) false if the document is not well formed (see methods to get error description, line and column number)<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- ============ METHOD DETAIL ========== --> </td> </tr></table> </body> </html>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.