有很多语法扩展。其中最重要的是XML字面量(参见第11.1.4节和11.1.5节):
var foo = <xml>
foo
</xml>;
var bar = <>
<tag attr={(1+2).toFixed(2)}/>
{foo}
</>;
上面的示例展示了XML代码中空根标签和JavaScript表达式的特殊情况。
你还有一些在ECMA-262中无效的表达式(参见第11.2节):
xml.@attr // get attribute attr
xml.* // get all child elements
xml.@* // get all attributes
xml..foo // get all <foo> tags
xml..foo.(@id == 1) // filter <foo> tags by id attribute
这里有命名空间(见11.1.2节):
xml.soap::foo // get <foo> child tags with namespace soap
xml.@soap::attr // get attribute with namespace soap
有一个默认的XML命名空间声明,语法上是非常不寻常的结构(见第12.1节):
default xml namespace = new Namespace("http://foo/bar");
最后,还有一种类似于for..in
的循环叫做for each...in
循环(见12.3节):
for each (var foo in xml)
{
}