【问题标题】:jquery remove tags from external files and save themjquery 从外部文件中删除标签并保存它们
【发布时间】:2010-10-04 13:42:20
【问题描述】:

您好,

我需要删除 XML 文件中的标签(大约 1000 个)。我用 jquery 尝试过,但没有成功:

<html>
<!--jquery app removes specific <t2_patch ...>-tag -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>

<button>Kill t2_patch-tags </button>
<script>
        $("button").click(function () {
    $('/home/dan/series14AreaListOnly.xml').remove('t2_patch');
});
</script>
</body>
</html>

我的目标是删除 300MB 大 XML 文件中的 t_patch -tags。到目前为止我所做的这种方法是否可行,或者我完全错了。如何保存更改? (因为 remove() 函数实际上并没有直接删除 xml 文件上的任何内容?)。

提前感谢您的任何提示并致以最诚挚的问候

丹尼尔

【问题讨论】:

    标签: jquery xml tags


    【解决方案1】:

    最好的办法是设置一个后端 php 脚本并 ping 它要删除的实体并等待回调,更快更可靠,更不容易被黑客入侵,因为如果有人这样做了:

     $('/home/dan/series14AreaListOnly.xml').remove('*');
    

    【讨论】:

      【解决方案2】:

      为什么不用 XSLT?还有,在XML中去掉tags是什么意思?

      如果您要删除元素,此样式表会删除输入中的任何 t2_patch 元素:

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="node()|@*">
              <xsl:copy>
                  <xsl:apply-templates select="node()|@*"/>
              </xsl:copy>
          </xsl:template>
          <xsl:template match="t2_patch"/>
      </xsl:stylesheet>
      

      如果您要删除元素但保留其内容,则此样式表:

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="node()|@*">
              <xsl:copy>
                  <xsl:apply-templates select="node()|@*"/>
              </xsl:copy>
          </xsl:template>
          <xsl:template match="t2_patch">
              <xsl:apply-templates select="node()"/>
          </xsl:template>
      </xsl:stylesheet>
      

      注意:覆盖身份规则。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-23
        • 1970-01-01
        • 2012-04-12
        • 1970-01-01
        • 1970-01-01
        • 2021-06-06
        • 2015-09-13
        • 1970-01-01
        相关资源
        最近更新 更多