JavaScript XML 文本节点是否有 4096 个字符的限制?

发布于 2024-08-16 08:05:47 字数 67 浏览 3 评论 0原文

为什么我总是只获得有效 XML 文本节点的前 4096 个字符? (使用 JavaScript...)文本节点是否有限?

How is it that I always get only the first 4096 chars of a valid XML text node? (using JavaScript...) is a text node limited?

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

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

发布评论

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

评论(2

峩卟喜欢 2024-08-23 08:05:47

是的。某些浏览器限制为 4096,并将较长的文本拆分为父元素的多个文本节点子节点。如果你查看 Apache CXF 的源代码,你会发现一些实用的 Java 脚本来处理这个问题(如果没有其他地方的话)。

// Firefox splits large text regions into multiple Text objects (4096 chars in
// each). Glue it back together.
function getNodeText(node) {
    var r = "";
    for (var x = 0;x < node.childNodes.length; x++) {
        r = r + node.childNodes[x].nodeValue;
    }
    return r;
}

另请参阅:

https://github.com/apache/cxf/blob/cxf-2.1.9/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils .js

了解附近的更多好东西。

Yes. Some browsers limit to 4096, and split longer texts into multiple text node children of the parent element. If you look at the source to Apache CXF you will find some utility Java script to deal with this, if no place else.

// Firefox splits large text regions into multiple Text objects (4096 chars in
// each). Glue it back together.
function getNodeText(node) {
    var r = "";
    for (var x = 0;x < node.childNodes.length; x++) {
        r = r + node.childNodes[x].nodeValue;
    }
    return r;
}

Also see:

https://github.com/apache/cxf/blob/cxf-2.1.9/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js

for more goodies in this neighborhood.

美人迟暮 2024-08-23 08:05:47

顺便说一句,您可以使用 normalize 方法将所有连续的 TextNode 合并为一个循环它们以获得文本。

by the way, you can use normalize method to join all contiguous TextNode into one instead of looping them to obtain the text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文