Solved

XML + XML Schema validation using PHP?

Posted on 2004-09-07
7
903 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

813 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

11 Experts available now in Live!

Get 1:1 Help Now