學xml http://www.w3schools.com/xml/default.asp
我們游戲里界面和與界面有關的很多邏輯都是寫在xml里面的,其中邏輯使用lua寫,嵌在xml中,用xmlSpy編輯。
xml中嵌入lua,比如
function max(a,b)
if a > b then
return a;
else
return b;
end
end
</script>
大于號 > 要寫成 > , 就是greater than的意思。同樣:
小于號 < < less than
這樣子lua沒有高亮顯示,搞得我看起來很痛苦,晚上突發奇想,從*.lua文件里讀,就可以用LuaEdit來編輯了,那我就可以按F6來check syntax了,哈哈
</script>
我從xml文件中把lua段粘貼到*.lua文件里時,忘了把>之類的符號換成 > 等,導致我查了很久,老子還跟蹤到luabind和lua的源代碼里面去,靠!faint!
幸虧LuaEdit有Check Syntax功能,幫助我檢查到了錯誤,深刻體會到了工具的好處,也更加堅信“人與動物的最大差別在于人類能夠制造工具并使用工具”!
要是再整得能單步調試,那就爽歪歪了!
All text in an XML document will be parsed by the parser.
Only text inside a CDATA section will be ignored by the parser.
Parsed Data
XML parsers normally parse all the text in an XML document.
When an XML element is parsed, the text between the XML tags is also parsed:
<message>This text is also parsed</message> |
The parser does this because XML elements can contain other elements, as in this example, where the <name> element contains two other elements (first and last):
<name><first>Bill</first><last>Gates</last></name> |
and the parser will break it up into sub-elements like this:
<name> <first>Bill</first> <last>Gates</last> </name> |
Escape Characters
Illegal XML characters have to be replaced by entity references.
If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. You cannot write something like this:
<message>if salary < 1000 then</message> |
To avoid this, you have to replace the "<" character with an entity reference, like this:
<message>if salary < 1000 then</message> |
There are 5 predefined entity references in XML:
< | < | less than |
> | > | greater than |
& | & | ampersand |
' | ' | apostrophe |
" | " | quotation mark |
Note: Only the characters "<" and "&" are strictly illegal in XML. Apostrophes, quotation marks and greater than signs are legal, but it is a good habit to replace them.
CDATA
Everything inside a CDATA section is ignored by the parser.
If your text contains a lot of "<" or "&" characters - as program code often does - the XML element can be defined as a CDATA section.
A CDATA section starts with "<![CDATA[" and ends with "]]>":
<script> <![CDATA[ function matchwo(a,b) { if (a < b && a < 0) then { return 1 } else { return 0 } } ]]> </script> |
In the example above, everything inside the CDATA section is ignored by the parser.
Notes on CDATA sections:
A CDATA section cannot contain the string "]]>", therefore, nested CDATA sections are not allowed.
Also make sure there are no spaces or line breaks inside the "]]>" string.