Click to See Complete Forum and Search --> : Can we validate an xml file before use the parser


niroshan
10-14-2005, 02:44 AM
Hi everyone,

Is there anyway i could validate and welform a xml file before send it to a parser.

I will explain my scenario so u`ll undestand what i want exactly.

Im writting a CMS using XML. I have used FCKeditor so admin can edit the contents using that and save the contents back to the xml file. The main requirement on this process is that all the contents pass from the FCKeditor needs to be validated and welform before it saves to the xml file.

I use SAX parser to write the contents back to the xml file. But if the FCKvalues are not welform or validated then the parser will fail and altimatly the saving process also fail.

So thats why im kind of wondering if there any way i can check the validity of the FCKeditor value before pass it to the PHP SAX parser.

Hope u`ll undestand my problem.

Any comments and suggestion are also really welcome.

Thanx in advance.

Regards,
Niroshan

Khalid Ali
10-16-2005, 12:02 PM
depends on which API you are using I know I can check the validity of an xml doc using Java DOM API before it actually creates the document..

niroshan
10-18-2005, 12:19 AM
Hi,
Thank you very much for the reply. Unfortunatly i cannot use JAVA DOM model becouse im using PHP instead of JAVA.
So im just wondering is there any way i can do this using PHP???


Regards,
Niroshan

Khalid Ali
10-18-2005, 01:50 PM
Normally most of the DOM implementaions do provide you with such functianlity.here is a link (http://www.wiki.cc/php/Dom_validation) that will show you how to use PHP to validate XML file

niroshan
10-19-2005, 12:05 AM
Hi,
Thank you very much for the reply. I went though the link you have given me but unfortunatly it didnt work for me. So i did some research on that and i found out in the PHP manually, to work DOM XML functions we need to install GNOME XML library (http://www.xmlsoft.org/).

In the manual it stated an warning message as,

This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.

Is it really unsafe to use DOM implementation for XML parsing? I have seen this warning message in many other sites also so thats why i used a SAX parser in my application.

So is there anyway i can validate an xml file without using a DOM model.?

Regards,
Niroshan