3

私は以下のようなxmlを持っています。

<!DOCTYPE parent [
<!ENTITY entity1 "value"> 
]>
<main>
<parent attr1="str1"
        attr2="str2">
<child childattr1="str3"
       childattr2="&entity1;" />
<child childattr1="str4"
       childattr2="&entity1;" />
</parent>
</main>

残りの xml ファイルはそのままにして、子要素をインデントする必要があります (つまり、dtd セクションとエンティティは削除せず、属性は新しい行に配置する必要があります)。xml は最終的に次のようになります。

<!DOCTYPE parent [
<!ENTITY entity1 "value"> 
]>
<main>
    <parent attr1="str1"
            attr2="str2">
        <child childattr1="str3"
               childattr2="&entity1;" />
        <child childattr1="str4"
               childattr2="&entity1;" />
    </parent>
</main>

と を使ってみxmllintましtidyた。xmllint子要素をインデントしていますが、属性を新しい行に保持していません。tidy一方、属性を新しい行に保持するオプションがありますが、子要素をインデントすることはできません。perl正規表現も使用してみました。これはおそらく XSLT で行うことができますが、私はそれに精通していません。

4

1 に答える 1

4

XML::Twigのユーティリティは、そのオプションであなたxml_ppが望むことをほとんど行うようです:indented_a

$ xml_pp -s indented_a foo.xml
<!DOCTYPE parent [
<!ENTITY entity1 "value">
]>
<main>
  <parent
      attr1="str1"
      attr2="str2">
    <child
        childattr1="str3"
        childattr2="&entity1;"
    />
    <child
        childattr1="str4"
        childattr2="&entity1;"
    />
  </parent>
</main>
于 2013-06-27T13:05:32.090 に答える