Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/08/2008, 13:15
Avatar de farra
farra
 
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 18 años, 7 meses
Puntos: 20
Exclamación

encontre una clase para validar pero no me funciona ya probe de todo y todavia no encuentro el problema....

este es el codigo:
Código PHP:
<?php
include_once("class_xml_check/class_xml_check.php");

$myxml='<?xml version="1.0"?>
<foo>
 <data id="1">
   <name>pepe</name>
   <num>2</num>
 </data>
 <data>
   <name>foo</name>
   <num>5</num>
 </data>
</foo>'
;

$check = new XML_check();
//if($check->check_url("http://www.w3.org/")) {
if($check->check_string($myxml)) {
  print(
"XML is well-formed<br/>");
  print(
"<pre>");
  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/>");
  print(
"</pre>");
} else {
  print(
"XML is not well-formed<br/>");
  print(
$check->get_full_error());
}
?>

help!

el codigo de class_xml_check.php es este:

Código PHP:
<?php
// ##################################################################################
// Title                     : Class XML_check
// Version                   : 1.0
// Author                    : Luis Argerich ([email protected])
// Last modification date    : 07-10-2002
// Description               : A class to check if documents are well formed
//                             XML reporting error msg,line and col if not or
//                             statistics about the document if it is well formed.
// ##################################################################################
// History: 
// 07-10-2002                : First version of this class.
// ##################################################################################
// To-Dos:
//
// ##################################################################################
// How to use it:
// Read the documentation in class_xml_check.html
// ##################################################################################

class XML_check {
  var 
$error_code;
  var 
$error_line;
  var 
$error_col;
  var 
$error_msg;
  var 
$size;
  var 
$elements;
  var 
$attributes;
  var 
$texts;
  var 
$text_size;
  
  function 
get_error_code() {
    return 
$this->error_code; 
  }
  
  function 
get_error_line() {
    return 
$this->error_line; 
  }
  
  function 
get_error_column() {
    return 
$this->error_col; 
  }
  
  function 
get_error_msg() {
    return 
$this->error_msg; 
  }
  
  function 
get_full_error() {
    return 
"Error: ".$this->error_msg." at line:".$this->error_line ." column:".$this->error_col;
  }
  
  function 
get_xml_size() {
    return 
$this->size; 
  }
  
  function 
get_xml_elements() {
    return 
$this->elements; 
  }
  
  function 
get_xml_attributes() {
    return 
$this->attributes; 
  }
  
  function 
get_xml_text_sections() {
    return 
$this->texts; 
  }
  
  function 
get_xml_text_size() {
    return 
$this->text_size; 
  }
  
  function 
check_url($url) {
    
$this->_init();
    
$this->parser = xml_parser_create_ns("",'^');
    
xml_set_object($this->parser,&$this);
    
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
    
xml_set_element_handler($this->parser, "_startElement", "_endElement");
    
xml_set_character_data_handler($this->parser,"_data");
    if (!(
$fp = fopen($url, "r"))) {
      
$this->error="Cannot open $rddl";
      return 
false;
    }
    while (
$data = fread($fp, 4096)) {
      
$this->size+=strlen($data);
      if (!
xml_parse($this->parser, $data, feof($fp))) {
        
$this->error_code = xml_get_error_code($this->parser);
        
$this->error_line = xml_get_current_line_number($this->parser);
        
$this->error_col = xml_get_current_column_number($this->parser);
        
$this->error_msg = xml_error_string($this->error_code);
        return 
false;                    
      }
    }
    
xml_parser_free($this->parser); 
    return 
true;
  }
  
  function 
_init() {
    
$this->error_code = '';
    
$this->$error_line = '';
    
$this->$error_col = '';
    
$this->$error_msg = '';
    
$this->$size = 0;
    
$this->$elements = 0;
    
$this->$attributes = 0;
    
$this->$texts = 0;
    
$this->$text_size = 0; 
  }
  
  function 
_startElement($parser,$name,$attrs) {
    
$this->elements++;
    
$this->attributes+=count($attrs);
  }
  
  function 
_endElement($parser,$name) {
    
  }
  
  function 
_data($parser,$data) {
    
$this->texts++;
    
$this->text_size+=strlen($data);
  }
  
  function 
check_string($xml) {
    
$this->_init();
    
$this->parser = xml_parser_create_ns("",'^');
    
xml_set_object($this->parser,&$this);
    
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
    
xml_set_element_handler($this->parser, "_startElement", "_endElement");
    
xml_set_character_data_handler($this->parser,"_data");
    
$this->size+=strlen($xml);
    if (!
xml_parse($this->parser, $xml, true)) {
      
$this->error_code = xml_get_error_code($this->parser);
      
$this->error_line = xml_get_current_line_number($this->parser);
      
$this->error_col = xml_get_current_column_number($this->parser);
      
$this->error_msg = xml_error_string($this->error_code);
      return 
false;                    
    }
    
xml_parser_free($this->parser); 
    return 
true;
  } 
  
  
}



?>
Los errores que me tira son:

Código:
Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in C:\wamp\www\sitio\class_xml_check\class_xml_check.php on line 75

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in C:\wamp\www\sitio\class_xml_check\class_xml_check.php on line 126

Fatal error: Cannot access empty property in C:\wamp\www\sitio\class_xml_check\class_xml_check.php on line 99
Tambien probe con otra clase pero tampoco funciona...

siempre me da que el feed no es valido, incluso cuando si lo es...

Codigo:

Código PHP:
<?php 

    
require_once("feed_validator.class.php"); 

    
$obj =& new feed_validator(); 
$url = 'http://www.lanacion.com.py/rss.php';
    
//if ($obj->validate("http://yahoo.com/")) 
    
if ($obj->validate($url)){
        print 
"Feed OK...\n"; 
    }else{
        print 
"Not valid."; 
    }

?>
Documentacion y fuente:
http://www.phpclasses.org/browse/file/13510.html
__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)

Última edición por j_aroche; 01/08/2008 a las 15:14