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? Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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!!! Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.