Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 使用正则表达式从另一个标记集中删除标记集_Xml_Regex_Bbedit - Fatal编程技术网

Xml 使用正则表达式从另一个标记集中删除标记集

Xml 使用正则表达式从另一个标记集中删除标记集,xml,regex,bbedit,Xml,Regex,Bbedit,我有一个很大的XML文件,我正在用BBEdit编辑 XML文件是旧日记的数字再现,其中包含包含在注释标记中的文本 <note>Example of a note.</note> 注释示例。 但是,有些注释标记的引号包含在嵌套的引号标记中 <note>Example of a note, but <quote>"here is a quotation within the note"</quote></note> 注释示

我有一个很大的XML文件,我正在用BBEdit编辑

XML文件是旧日记的数字再现,其中包含包含在注释标记中的文本

<note>Example of a note.</note>
注释示例。
但是,有些注释标记的引号包含在嵌套的引号标记中

<note>Example of a note, but <quote>"here is a quotation within the note"</quote></note>
注释示例,但“注释中有引用”
我需要从note标签中删除quote的所有实例,同时保留quote标签的实际内容。因此,这个例子将变成:

<note>Example of a note, but "here is a quotation within the note"</note>
注释示例,但“注释中有引用”
我已经在BBEdit中使用GREP成功地删除了其中一些,但是我开始被一些更复杂的note标记所困扰,这些标记跨越了几行,或者在两组不同的标记之间有文本。例如:

<note>Example of a note, <quote>"with a quotation"</quote> and a <quote>"second quotation"</quote> along with some text outside of the quotation before the end of the note.</note>
注释示例,“带引号”和“第二个引号”以及注释结尾前引号外的一些文本。
有些报价可以超过10行。在我的正则表达式中使用\r似乎没有帮助

我还应该说,quote标记可以存在于note标记之外,这排除了批量查找/?quote并删除它的可能性。我仍然需要在文档中使用quote标记,而不是note标记

<note>Example of a note.</note>

非常感谢您的帮助。

使用XSLT非常简单:

<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="quote">
    <xsl:apply-templates select="node()|@*" />
  </xsl:template>
</xsl:stylesheet>


使用您选择的XSLT处理器将此样式表应用于XML文件。例如,有一些工具可以在命令行上操作。

如果不限制XML的形成,我很确定这超出了常规语言的范围,进入了上下文无关的语言,这意味着正则表达式对您没有帮助。如果XML的结构很简单(没有嵌套在节点中的节点或嵌套在引号中的引号),那么您可能可以使用
\1\2\3
全局替换
(!)(!)(!)
,但您可能使用了错误的工具来执行该作业。作为其他答案之一,XSLT可以帮助您,或者您可以使用XML解析库来编写一个简单的程序来去除您正在寻找的标记