Hi I am using libxml2 to validate an XML file using a Schema. Like this: schema = XML::Schema.from_string(schema_string) parser = XML::Parser.new parser.string = xml doc = parser.parse result = doc.validate_schema(schema) This works and if the XML doc is invalid the error is written to standard output. Is there a way to capture this output? I need to relay this information to the client application. Grateful for any assistance. Kindest regards Erik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erik Lindblad
2008-Aug-27 09:59 UTC
Re: Getting error information from XML Schema validation
I found the solution in the libxml-ruby test cases. Viva TDD! If anyone else is interested this is a pattern for testing it: schema = XML::Schema.from_string(schema_string) parser = XML::Parser.new parser.string = xml doc = parser.parse messages = Hash.new assert(!doc.validate_schema(schema) do |message, error| messages[message] = error end) expected = {"Element ''customer_ip'': This element is not expected. Expected is ( password ).\n" => true} assert_equal expected, messages Hope it helps. Regards Erik On 27 Aug, 10:36, Erik Lindblad <e...-gTO0lQh45js@public.gmane.org> wrote:> Hi > > I am using libxml2 to validate an XML file using a Schema. Like this: > > schema = XML::Schema.from_string(schema_string) > parser = XML::Parser.new > parser.string = xml > doc = parser.parse > result = doc.validate_schema(schema) > > This works and if the XML doc is invalid the error is written to > standard output. Is there a way to capture this output? I need to > relay this information to the client application. Grateful for any > assistance. > > Kindest regards > > Erik--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---