JavaScript + e4x:如何测试元素是否为空?

发布于 2024-12-29 02:20:18 字数 125 浏览 0 评论 0原文

有没有办法使用 e4x 测试 XML 元素是否为空?

例如,如果我有一个元素 ,我想返回 true,但如果我有另一个具有任何属性、子元素或文本的元素,我想返回 false。

Is there a way to test whether an XML element is empty using e4x?

e.g. if I have an element <foo />, I want to return true, but if I have another element that has any attributes, child elements, or text, I want to return false.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2025-01-05 02:20:18

我刚刚艰难地浏览了 e4x 上的 ECMA-357 v2 规范; XML 节点的方法在 13.4.4 节中列出,并且此测试没有有用的 isXXX()hasXXX() 方法;最简单的方法似乎如下:

function isEmptyNode(node){ 
  return node.children().length() == 0 && node.attributes().length() == 0;
}

I just slogged through the ECMA-357 v2 spec on e4x; the methods for XML nodes are listed in section 13.4.4, and there are no useful isXXX() or hasXXX() methods for this test; the simplest way to do it seems to be the following:

function isEmptyNode(node){ 
  return node.children().length() == 0 && node.attributes().length() == 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文