0

If user is entering normal string, I need not to convert it to Xml format.. If I get Html data, then I have to convert into Xml. How can I check that without using Regex?

Sangeet
  • 145
  • 3
  • 9

2 Answers2

0

Html and Xml always Starts with < Tag. the simplest without regex way of checking if it not Start with < then it is normal String. Otherwise If it start with < then it may be normal String or HTML too.

And Html contains <html> Tag.

Khalid Shah
  • 3,132
  • 3
  • 20
  • 39
0

Try the following function

function isHTML(str) {
     var a = document.createElement('div');
     a.innerHTML = str;

     for (var c = a.childNodes, i = c.length; i--; ) {
     if (c[i].nodeType == 1) return true; 
     }
    return false;
}
chinmayan
  • 1,304
  • 14
  • 13