Solved

XML + XML Schema validation using PHP?

Posted on 2004-09-07
7
900 Views
Last Modified: 2013-11-19
How can I validate an XML file described by XML Schema using PHP? I've searched for a while now and I cannot find anything about it. I think there is something on XML file + DTD validation on PEAR, but I'm looking for XML + XML Schema validation...

Thank you.
0
Comment
Question by:newaira
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
With php5 it should be possible, but not with php4
see
http://www.mail-archive.com/php-general@lists.php.net/msg149242.html
or
http://de3.php.net/manual/en/function.dom-domdocument-schemavalidate.php (The function which should do the schema-validation in php5)
0
 
LVL 3

Author Comment

by:newaira
Comment Utility
That is no good because I'm working in php 4.3.5
0
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
I don't think that there are php-classes or functions written by other that would do that in PHP as that is a very complex thing to do (rewrite a lot of parts of the libxml2 in PHP). One hard way to go is to write your own php-extension for PHP4 that does call the validate via libxml2 C-functions
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:newaira
Comment Utility
Do you know a good DTD vallidator? I am trying to use the one at http://pear.php.net/package/XML_DTD/ but it's all messed up...
0
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
No I don't know of a good DTD-Validator written in PHP or usable in PHP. Maybe there is a shell-command like xmllint from www.w3c.org and then do a exec('xmllint --option filename')
0
 
LVL 3

Author Comment

by:newaira
Comment Utility
Well I found a good XML + XML Scheme validator!

1. Go to http://www.w3.org/2001/03/webdata/xsv
2. Enter the web path to the xml file to be validated against an XML schema.
3. Choose the 'xml, but labelled text/plain' radio button.
4. Get results. -> An XML file is displayed with the error messages (if any).

To use this in PHP I just used file_get_contents of the URL given after clicking 'Get results' and checked for any errors. Something like this:

$validate_xml = file_get_contents("http://www.w3.org/2001/03/webdata/xsv?docAddrs=http%3A%2F%2Fuwssa.org%2Fmodules%2FMembers%2Fmembers.xml&style=text");

if (substr_count(strtolower($validate_xml), "<fsm>") >= 1)
  echo "members.xml is invalid.";
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
Comment Utility
Please read entire thread.  Asker solved or content important.
Closed, 250 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now