开发者

Page not validating because of xml in a script tag

I'm trying to get a page to validate (http://validator.w3.org) and it complains about some xml I have inside a script tag.

How can I resolve this? Am I supposed to have something around the content of my script tag saying "don't look at me"?

Line 68, column 114: end t开发者_StackOverflowag for element "STR_PROCESSING" which is not open

>Processing....</STR_Processing>

Code:

<script type="text/javascript" defer="defer">
var sML_XML='<STR_Processing>Processing....</STR_Processing><STR_OK>...';
</script>


You have to place a backslash (\) before the slashes, when it is in a script.
Look here: http://www.htmlhelp.com/tools/validator/problems.html#script

For example:
var test="<b>something<\/b>";
instead of:
var test="<b>something</b>";

This should validate with no errors.


If you are using tag in strings you can do this :

 var yourHTML = "<STR_PROCESSING>YourData<" + "/STR_PROCESSING>";


The correct XML way is to use CDATA section identifiers:

<script type="text/javascript">//<![CDATA[
/* code */
//]]></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜