hmdnawaz Posted December 22, 2010 Share Posted December 22, 2010 <?xml version="1.0" encoding="ISO-8859-1"?> <Note> <from> Ahmad </from> <to> Yasir </to> <body> hello yasir. </Note> Above is my xml file which misses the ending tag of <body>. i want a php program that will detect this error and also fix the error and place the ending tag. can someone help me? Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/ Share on other sites More sharing options...
johnny86 Posted December 22, 2010 Share Posted December 22, 2010 Use DOMDocument class to validate your output: http://fi.php.net/domdocument http://fi.php.net/manual/en/domdocument.validate.php Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/#findComment-1150175 Share on other sites More sharing options...
hmdnawaz Posted December 22, 2010 Author Share Posted December 22, 2010 Thanks for your reply. but it gives me the error that "" Warning: DOMDocument::validate() [domdocument.validate]: no DTD found! in D:\wamp\www\ReadXml\readxml.php on line 18"" now what is the problem? Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/#findComment-1150177 Share on other sites More sharing options...
johnny86 Posted December 22, 2010 Share Posted December 22, 2010 You need to specify our document type definition at the top of your xml file. <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> This way the XML parser will know what to expect. It will validate your XML against that info. Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/#findComment-1150183 Share on other sites More sharing options...
hmdnawaz Posted December 22, 2010 Author Share Posted December 22, 2010 the links you provided only checks that the document is valid or not. and i want to check the document and if there is no end tag of a tag then add the ending tag of that tag. Will get all nodes of the document and store them in a variable and then perform checks on that variable. Hope you get my problem!!! Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/#findComment-1150195 Share on other sites More sharing options...
johnny86 Posted December 22, 2010 Share Posted December 22, 2010 Then the job gets a bit harder. I don't know any XML parser that would also validate the invalid parts of xml string. If you don't know what the XML string should contain. Then it is a very big job to write parser for that. But if you know what you need to validate then you could write your own validator which checks that all tags are closed in the right order. Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/#findComment-1150201 Share on other sites More sharing options...
hmdnawaz Posted December 22, 2010 Author Share Posted December 22, 2010 how can i check that all tags are closed properly in perfect order? and if a tag is not closed or not nested properly then how can i fix it using php? Link to comment https://forums.phpfreaks.com/topic/222356-how-to-fix-errors-in-xml-file-using-php-program/#findComment-1150203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.