Solved

XML + XML Schema validation using PHP?

Posted on 2004-09-07
7
902 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
ID: 11998787
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
ID: 11998817
That is no good because I'm working in php 4.3.5
0
 
LVL 48

Expert Comment

by:hernst42
ID: 11998905
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:newaira
ID: 12007434
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
ID: 12007958
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
ID: 12008435
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
ID: 12009222
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

23 Experts available now in Live!

Get 1:1 Help Now