0

引用< >ではなくコンテンツに含まれる XML/HTML (epub) ドキュメントがあります。" "コンテンツのみを置き換えて、正規表現をそのままにして< >おく可能性はありますか?<tags>

4

1 に答える 1

1

XML の解析に Regex を使用しないでください

あなたの質問は完全に明確ではありませんが、XML には、引用符に変更したいテキスト値が含ま<れているようです。>これは、XSLT を使用してかなり簡単に実行できます。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | *">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:value-of select="translate(., '&lt;&gt;', '&quot;&quot;')"/>
  </xsl:template>
</xsl:stylesheet>

この入力で実行すると:

<root>
  <item>And he said &lt;hello!&gt;.</item>
  <item>&lt;hello!&gt;, he said</item>
  <section>
    <content>&lt;What's up&gt;</content>
  </section>
</root>

それは生成します:

<root>
  <item>And he said "hello!".</item>
  <item>"hello!", he said</item>
  <section>
    <content>"What's up"</content>
  </section>
</root>

ドキュメント内のテキストに、引用符に変換したくない<s およびsが含まれるリスクはありますか?>

于 2013-02-08T05:12:39.210 に答える