자바스크립트로 xml 문법 검사하기
xml validator - xml 오류 검사
<script>
function validateXML(txt)
{
// code for IE
if (window.ActiveXObject)
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(document.all(txt).value);
if(xmlDoc.parseError.errorCode!=0)
{
txt="Error Code: " + xmlDoc.parseError.errorCode + "\n";
txt=txt+"Error Reason: " + xmlDoc.parseError.reason;
txt=txt+"Error Line: " + xmlDoc.parseError.line;
alert(txt);
}
else
{
alert("No errors found");
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation.createDocument)
{
try
{
var text=document.getElementById(txt).value;
var parser=new DOMParser();
var xmlDoc=parser.parseFromString(text,"application/xml");
}
catch(err)
{
alert(err.message)
}
if (xmlDoc.getElementsByTagName("parsererror").length>0)
{
checkErrorXML(xmlDoc.getElementsByTagName("parsererror")[0]);
alert(xt)
}
else
{
alert("No errors found");
}
}
else
{
alert('Your browser cannot handle XML validation');
}
}
</script>
<textarea name="xml_check" id="xml_check" style="width:500px; height:200px;"></textarea>
<input type="button" onclick="validateXML(this.value);" value="xml_check">