# Validate xml

**URL:** <https://www.ruby-forum.com/t/validate-xml/140081>\
**Category:** Ruby\
**Created:** [June 10, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/validate-xml/140081 "2008-06-10T17:40:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [June 10, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/validate-xml/140081/1 "2008-06-10T17:40:35Z")

</div>

anyone knows how to validate an xml string a schema using with libxml-  
ruby?  
validate\_schema method is only available for XML::Document but not for  
XML::Reader.  
regards.

---

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [July 14, 2008, 5:52am UTC](https://www.ruby-forum.com/t/validate-xml/140081/2 "2008-07-14T05:52:20Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

You can create a document from your string:

xp = XML::Parser.new  
xp.string = your\_string  
xml\_doc = xp.parse

Tiago M.

jney wrote:  
| anyone knows how to validate an xml string a schema using with libxml-  
| ruby?  
| validate\_schema method is only available for XML::Document but not for  
| XML::Reader.  
| regards.  
|  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v2.0.9 (GNU/Linux)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkh6zSUACgkQxFuRTtCTMvLnhwCeJtDOWw1tra3z9oBxH9Syo8HE  
MToAnixT8tQJyB/pAPQ7r8kcUalPGin5  
=bbEL  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [April 20, 2009, 7:45pm UTC](https://www.ruby-forum.com/t/validate-xml/140081/3 "2009-04-20T19:45:15Z")

</div>

Jean-sÃ©bastien Jney wrote:

> anyone knows how to validate an xml string a schema using with libxml-  
> ruby?  
> validate\_schema method is only available for XML::Document but not for  
> XML::Reader.  
> regards.

Hello,

I saw your post searching some help for LibXML.

I’m trying to validate via LibXML::XML::Schema like it’s written in the  
official documentation:

[http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Schema.html](http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Schema.html)

“”"

# parse schema as xml document

schema\_document = XML::Document.file(‘schema.rng’)

# prepare schema for validation

schema = XML::Schema.document(schema\_document)

# parse xml document to be validated

instance = XML::Document.file(‘instance.xml’)

# validate

instance.validate\_schema(schema)

“”"

…but there is something wrong about installation because I can’t use  
the validation method. I don’t have it. I was looking around and I can’t  
see the method anywhere.

Do you have any idea??

P.S. I’m using Leopard as SO and I haven’t changed anything about  
libxml2.

Thanks in advance,  
Raul.
