Page 1 of 1

Validating XML files against an XML schema

Posted: Sat Mar 31, 2007 10:40 am
by jayshields
Basically, I've written up an XML file and an XSD and I want to see if the XML validates against the XSD. I've already validated my XSD file via the W3C validator.

Google seems to be pointing me to code snippets which can do this, but I just want a standalone program. So far I've found one, but it's only a trial version and you have to install .NET framework amonst other things before you attempt to install it.

Anyone got any programs to do this?

Thanks.

Also, I have no experience with XSL; but I'm wanting to output my XML file in a simple HTML table. Just two columns with element name in the left and value in the right. Shouldn't be too hard but I can't find any good information on the net anywhere. Can someone point me to a tutorial or anything about this?

Posted: Sat Mar 31, 2007 10:47 am
by nickvd
If you use firefox to view the xml file, and as long as it can read the DTD, then shouldn't it complain if it finds an error?

Posted: Sat Mar 31, 2007 10:52 am
by jayshields
I thought it might do, but how and where would it report errors?

Posted: Sat Mar 31, 2007 10:56 am
by nickvd
Right in the content window... I remember seeing a yellow background with red text, but it's been a while since I've had to work directly with xml

Posted: Sat Mar 31, 2007 11:43 am
by nickvd
What a coincidence... In searching for an online css compressor, I came across http://mathiasbynens.be/archive/2005/09/css-compressors Which shows what I was thinking about.

Posted: Sat Mar 31, 2007 12:02 pm
by jayshields
Hmmm. I can't seem to generate anything like that. Even if I completely screw up my XSD.

Posted: Sun Apr 01, 2007 7:03 am
by Ollie Saunders
isn't there a validate() method on DOMDocument?

I'm curious, is there a difference between DTD and XSD?

Posted: Sun Apr 01, 2007 10:21 am
by timvw
ole wrote:'m curious, is there a difference between DTD and XSD?
Yes... And google can easily tell you the exact the differences...

Posted: Fri Apr 06, 2007 8:28 am
by volka
libxml2 comes with the program xmllint
Usage : xmllint [options] XMLfiles ...
[...]
--relaxng schema : do RelaxNG validation against the schema
--schema schema : do validation against the WXS schema
--schematron schema : do validation against a schematron
and btw php 5 can do it, too
relaxNG example:

Code: Select all

<?php
$docA = DOMDocument::loadxml(
'<addressBook>
  <card>
    <name>John Smith</name>
    <email>js@example.com</email>
  </card>
  <card>
    <name>Fred Bloggs</name>
    <email>fb@example.net</email>
  </card>
</addressBook>');

$b = $docA->relaxNGValidateSource(
'<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
  <zeroOrMore>
    <element name="card">
      <element name="name">
        <text/>
      </element>
      <element name="email">
        <text/>
      </element>
    </element>
  </zeroOrMore>
</element>');


var_dump($b);