Detailed description and usage:
This class is very easy to use, this is a very simple example:
$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 ");
print($check->get_full_error());
}
You can use check url instead, for example:
if($check->check_url("http://www.w3.org/")) {
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 ");
print($check->get_full_error());
}
So we know the W3C home page is well formed XHTML :-)
Documentation
Classes
XML_check
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.
Method Summary |
integer |
get_error_code()
Returns an error code if the source is not well formed |
integer |
get_error_line()
Returns the line number where an error was detected |
integer |
get_error_column()
Gets the column number where the parser failed |
string |
get_error_msg()
This method returns the error message if the source is not well formed |
string |
get_full_error()
Returns a complete error message if the source is not well formed |
integer |
get_xml_size()
Returns XML document size |
integer |
get_xml_elements()
Returns the number of elements in the document |
integer |
get_xml_attributes()
Returns the number of attributes in the document |
integer |
get_xml_text_sections()
Returns the number of character data sections in the document |
integer |
get_xml_text_size()
Returns the size of the text sections in the document |
boolean |
check_url(string $url)
Checks if a URL is well formed XML |
boolean |
check_string(string $url)
Checks if a PHP string is well formed XML |
get_error_code
integer get_error_code()
- This method returns an error code number if the source wasn't well formed
-
- Parameters:
-
- Returns:
- An error number
- Throws:
None
get_error_line
integer get_error_line()
- If the data source is not well formed this method can be used to get the line number where the parser failed.
-
- Parameters:
-
- Returns:
- The line number where the parser failed.
- Throws:
None
get_error_column
integer get_error_column()
- If the source being checked is not well formed this method can be used to return the column number where the error was detected
-
- Parameters:
-
- Returns:
- The column number where the parser failed
- Throws:
None
get_error_msg
string get_error_msg()
- If the data source being validated is not well formed this method can be used to return an error message describing the error.
-
- Parameters:
-
- Returns:
- The error message if the parser fails.
- Throws:
None
get_full_error
string get_full_error()
- 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.
-
- Parameters:
-
- Returns:
- An string containing the error message, the line number and column number.
- Throws:
None
get_xml_size
integer get_xml_size()
- If the source is well formed this method returns the document size in bytes.
-
- Parameters:
-
- Returns:
- The document size in bytes.
- Throws:
None
get_xml_elements
integer get_xml_elements()
- If the document was well formed this method returns the number of XML elements in the document
-
- Parameters:
-
- Returns:
- The number of elements in the document
- Throws:
None
get_xml_attributes
integer get_xml_attributes()
- If the source was well formed this method returns the number of XML attributes seen in the document
-
- Parameters:
-
- Returns:
- The number of XML attributes in the document
- Throws:
None
get_xml_text_sections
integer get_xml_text_sections()
- If the source is well formed this method returns the number of character data sections reported by the parser.
-
- Parameters:
-
- Returns:
- The number of character data sections in the document
- Throws:
None
get_xml_text_size
integer get_xml_text_size()
- If the source is well formed this method returns the size of all the character data sections found in the document
-
- Parameters:
-
- Returns:
- The size of all the character data sections in the document
- Throws:
None
check_url
boolean check_url(string $url)
- 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.
-
- Parameters:
-
$url - The URL to be checked
- Returns:
- 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)
- Throws:
None
check_string
boolean check_string(string $url)
- 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.
-
- Parameters:
-
- Returns:
- 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)
- Throws:
None
|