# XML Validation

**URL:** <https://www.ruby-forum.com/t/xml-validation/126395>\
**Category:** Ruby\
**Created:** [January 17, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/xml-validation/126395 "2008-01-17T23:17:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangoosta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mangoosta](https://www.ruby-forum.com/u/mangoosta)\
**Post date:** [January 17, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/xml-validation/126395/1 "2008-01-17T23:17:24Z")

</div>

Hello,

I need to validate XML documents in Ruby. I was told that REXML can’t  
perform validation, thus I tried using libxml.

SaxParser can’t validate against a given DTD, so I tried DOM Parser.  
But I can’t find a way to get DOCTYPE from Document resulting from  
parsing. I could find DTD file with a regexp against document source,  
but it seems quite unefficient to me.

Is there a way to properly validate against a DTD using libxml-ruby or  
is there a gem providing such a feature ?

NOTE: please don’t try to convince me that I don"t need validation!

---

<div class="post-metadata">

**Author:** ![mangoosta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mangoosta](https://www.ruby-forum.com/u/mangoosta)\
**Post date:** [January 17, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/xml-validation/126395/2 "2008-01-17T23:27:22Z")

</div>

Michel C. wrote:

> NOTE: please don’t try to convince me that I don"t need validation!

I wouldn’t think of it. XML, now, that’s something you don’t need. 😉

---

<div class="post-metadata">

**Author:** ![mangoosta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mangoosta](https://www.ruby-forum.com/u/mangoosta)\
**Post date:** [January 17, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/xml-validation/126395/3 "2008-01-17T23:58:02Z")

</div>

Le 17 janv. 08 à 23:24, Joel VanderWerf a écrit :

> Michel C. wrote:
> 
> > NOTE: please don’t try to convince me that I don"t need validation!
> 
> I wouldn’t think of it. XML, now, that’s something you don’t need. 😉

Well done ;o)

Now, do you know a replacement for structured document format? YAML is  
great, but I can’t figure how to use it for that purpose… RDoc is  
great for README files, but it ends with hugly HTML tags for more  
complex documents. SGML is great also, but writing a DTD is far too  
complex. LaTeX is great too, but I can’t parse it. That’s why I’m  
stuck with XML and need validation.
