JavaScript & XML: validate an XML document
I think we all know how to use XML documents. For example RSS feeds are basically XML files, as well as sitemaps. Those files may be very important when managing a web site, but those examples are just a small part of the common use of XML documents. Just to make things clear, another example: when you export a Blogger blog, the file you get is an XML file.
When I've written the article on how to create an RSS feed, I discovered a very useful JavaScript snippet that helps us to validate an XML file.
Unfortunately I don't remember where I got it, but, even if I surely rearranged it, if you know the original source, please let me know so that I can give due credit to the author.
Ok, said that, let's see how to do it.
The code
First of all, let's create a form like the following:
Then we have a button which will trigger the Validate() function:
Now, you may wonder what res is. Well, it's quite easy: we use a HTML element to show the results of the validation process. So somewhere on the page we need to insert the following:
Let me know what you think.
When I've written the article on how to create an RSS feed, I discovered a very useful JavaScript snippet that helps us to validate an XML file.
Unfortunately I don't remember where I got it, but, even if I surely rearranged it, if you know the original source, please let me know so that I can give due credit to the author.
Ok, said that, let's see how to do it.
The code
First of all, let's create a form like the following:
Then we have a button which will trigger the Validate() function:
Now, you may wonder what res is. Well, it's quite easy: we use a HTML element to show the results of the validation process. So somewhere on the page we need to insert the following:
Let me know what you think.