[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nyphp-talk
Subject:    Re: [nyphp-talk] Transforming XML with XSL (XsltProcessor problems)
From:       Ben Sgro <ben () projectskyline ! com>
Date:       2009-03-13 18:29:55
Message-ID: 49BAA623.4040009 () projectskyline ! com
[Download RAW message or body]

Hey,

Thanks for the feedback and the sample code.
I'm going to look over this in more detail today.

Thanks again everyone!

- Ben

Daniel Convissor wrote:
> Hey Folks:
>
> On Thu, Mar 12, 2009 at 09:44:08PM -0400, Ajai Khattri wrote:
>   
>> I have to say, the error reporting for the XML and XSLT functions are 
>> terrible.
>>     
>
> Here's how I load XML.  Requres track_errors to be on.  Sorry about the 
> line wrapping.
>
>
> $xml_string = '';
> $schema_file = '';
>
> if (($dom = @DOMDocument::loadXML($xml_string)) == false) {
>     $error = 'Malformed XML: ' . $php_errormsg;
> } elseif ((@$dom->schemaValidate($schema_file)) == false) {
>     $error = 'XML violates schema ' . $schema_file . ': '
>             . format_schemavalidate_error($php_errormsg);
> } else {
>     if (($sxml = @simplexml_import_dom($dom)) === false) {
>         $error = 'Malformed XML (SimpleXML): ' . $php_errormsg;
>     }
> }
>
> if (!empty($error)) {
>     // process...
> }
>
>
>
> /**
>  * Boils down XML schema validation error messages into something
>  * humans can easily comprehend
>  *
>  * @param string $error  the $php_errormsg produced by DOM
>  *                       schemaValidate()
>  *
>  * @return string
>  */
> function format_schemavalidate_error($error) {
>     $error = preg_replace('/\s+/', ' ', $error);
>
>     if (preg_match("/The element: '([^']+)'/", $error, $match)) {
>         $error = $match[1] . ' has invalid value . ';
>     } elseif (preg_match("/Element '([^']+)', attribute '([^']+)'/", 
> $error, $match)) {
>         $error = $match[2] . ' attribute of ' . $match[1] . ' has invalid 
> value . ';
>     } elseif (preg_match("/Element '([^']+)': The attribute '([^']+)' is 
> required/", $error, $match)) {
>         $error = $match[2] . ' attribute of ' . $match[1] . ' is missing 
> . ';
>     } elseif (preg_match("/is not a valid value of the atomic type 
> '({.*})?([^']+)'/", $error, $match)) {
>         $error = $match[2] . ' has invalid value . ';
>     } elseif (preg_match('/Expecting: ([^.]+)/', $error, $match)) {
>         $error = $match[1] . ' is missing . ';
>     } elseif (preg_match('/(Expected is|Expected is one of) \( 
> ({.*})?([^.]+) \)/', $error, $match)) {
>         $error = $match[3] . ' is missing . ';
>     }
>
>     return $error;
> }
>
>
> Enjoy,
>
> --Dan
>
>   
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic