2012-03-28 4 views
1

2つのxml形式で与えられる一般的な方法は何ですか?そして、最初のフォーマットから正規表現への変換についてどう思いますか? <subgroupones>はありますか?基本的に<global>以外の属性を持たない<tags>のいずれかを削除するか、より洗練された方法があれば削除してください。xml一般的な練習とグループを削除する

<global> 
    <groupone name="bce"> 
     <subgroupones> 
      <subsgroupone name="a" /> 
      <subsgroupone name="b" /> 
      <subsgroupone name="c" /> 
     </subgroupones> 
    <groupone> 
</global> 

<global> 
    <groupone name="bce"> 
      <subsgroupone name="a" /> 
      <subsgroupone name="b" /> 
      <subsgroupone name="c" /> 
    <groupone> 
</global> 

答えて

2

XMLからXMLへの変換は、ほとんどの場合、スタイルシート変換(XSLT)によって最もよく処理されます。 PHPが組み込まれているXSLT処理するためのライブラリ:

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

出力例:たとえばhttp://php.net/manual/en/book.xslt.php

を、ここに(常に含まれ<global>を除く)属性を持つ要素のみをコピーするXSLTです(その余分なスペースを削除する方法はまだわからない):

<?xml version="1.0" encoding="UTF-8"?><global> 
    <groupone name="bce"> 

      <subsgroupone name="a"/> 
      <subsgroupone name="b"/> 
      <subsgroupone name="c"/> 

    </groupone> 
</global> 

あなたはこのツールを試すことができます。http://xslttest.appspot.com/

関連する問題