2010-10-04 46 views
0

問候,jquery從外部文件中刪除標籤並保存它們

我需要刪除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標籤。這種做法到目前爲止還沒有確定,還是我完全錯了。我如何保存更改? (因爲remove()函數實際上不會直接在xml文件上刪除任何內容?)。

預先感謝任何提示與問候

丹尼亞爾

回答

0

最好的辦法是建立一個後端PHP腳本和ping到它刪除的內容實體,並等待回調,速度更快,可靠,不太可行,因爲如果有人這樣做:

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

爲什麼不XSLT?而且,在XML中刪除標籤的含義是什麼?

如果你的意思是剝離的元素,這個樣式表刪除輸入任何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> 

注意:覆蓋身份規則。

相關問題