2012-07-27 4 views
1

XSD 파일에 대해 XML의 유효성을 검사하고 오류가 있으면 가져오고 싶습니다.오류가있는 XSD에 대해 XML 유효성을 확인하십시오.

DOM에서는 사용하지만 XMLReader에서는 사용하면 정상적으로 작동합니다. 지금까지 두 가지 모두 libxml 라이브러리를 사용하고 있으므로 XMLReader 용으로 사용해 보려고했지만 행운은 없었습니다.

감사

DOM 스키마를 설정 한 후

libxml_use_internal_errors(true); 

if (! $xml->schemaValidate($xsd_file)) 
{ 
    get_errors(); 
    exit; 
} 

function get_errors() 
{ 
    $messages = null; 
    $errors  = libxml_get_errors(); 

    foreach ($errors as $error) 
    { 
     switch ($error->level) 
     { 
      case LIBXML_ERR_ERROR: 
       $messages .= 'Error ' . $error->code . $error->message; 
       break; 

      case LIBXML_ERR_WARNING: 
       $messages .= 'Warning ' . $error->code . $error->message; 
       break; 

      case LIBXML_ERR_FATAL: 
       $messages .= 'Fatal ' . $error->code . $error->message; 
       break; 
     } 

     echo $messages .= ($error->file) ? $error->file : $error->line; 
    } 
} 

는 XmlReader를

libxml_use_internal_errors(true); 

//This returns true all times whether XML has faults or not 
if (! $reader->setSchema($xsd_file)) 
{ 
    //This echos nothing whether XML has faults or not 
    get_errors(); 
} 

답변

0

(위와 같은 오류 기능이 작동하지 않습니다) (미세 작품) , 나는 어떤 read() 또는 isValid()도 보지 않습니다, 그래서 어떻게 에러를 얻을 수 있습니까? documentation (PHP로 가정)을 살펴보면 아이디어를 얻을 수 있습니다.

+0

문제는 XML, XSD, 파서 등에서 매우 새로운 점입니다. 모든 문서를 읽었지만 문제가 해결되지 않았습니다. isValid() 다른 함수를 함께 넣으려고했으나 아무 것도 변경되지 않았습니다. 그것도 봤 거든. 나는 더 많은 경험이나 도움이 필요하다고 생각합니다. – BentCoder

관련 문제