JavaScript+;E4X:如何测试元素是否有文本节点?

JavaScript+;E4X:如何测试元素是否有文本节点?,javascript,xml,parsing,text,e4x,Javascript,Xml,Parsing,Text,E4x,在E4X中,我知道如何测试元素是否具有特定属性,但如何测试元素是否具有文本节点 js>x = <foo><bar /><baz attr1="123" /><quux>some random text</quux></foo> <foo> <bar/> <baz attr1="123"/> <quux>some random text</quux>

在E4X中,我知道如何测试元素是否具有特定属性,但如何测试元素是否具有文本节点

js>x = <foo><bar /><baz attr1="123" /><quux>some random text</quux></foo>
<foo>
  <bar/>
  <baz attr1="123"/>
  <quux>some random text</quux>
</foo>
js>'@attr1' in x.baz
true
js>'@attr1' in x.quux
false
js>x=一些随机文本
一些随机文本
js>x.baz中的“@attr1”
真的
js>x.qux中的“@attr1”
假的
对没有属性或子元素的元素使用该方法:

x.quux.hasSimpleContent()
使用RegExp删除标记和空格以聚合文本节点:

Boolean(x.toString().replace(/<.*?\>/g,"").replace(/\W/g,"").length)
Boolean(x.toString().replace(//g,”).replace(//\W/g,”).length)
对没有属性或子元素的元素使用该方法:

x.quux.hasSimpleContent()
使用RegExp删除标记和空格以聚合文本节点:

Boolean(x.toString().replace(/<.*?\>/g,"").replace(/\W/g,"").length)
Boolean(x.toString().replace(//g,”).replace(//\W/g,”).length)