Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XML + XML Schema validation using PHP?

Posted on 2004-09-07
7
Medium Priority
?
916 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

916 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