0

以下は、基本的に単なる xml ファイルである大きな fxg ファイルからのコードの抜粋です。

<RichText x="14.1655" y="46.5674" columnGap="18" columnCount="1" textAlign="left" fontFamily="Bootstrap" color="#53836A" whiteSpaceCollapse="preserve" width="202.712" height="13.334" s7:caps="none" s7:colorName="" s7:colorValue="#B24FA41C" s7:colorspace="cmyk" s7:elementID="line1" s7:fill="true" s7:fillOverprint="false" s7:firstBaselineOffset="ascent" s7:joints="miter" s7:maxFontSize="12" s7:miterLimit="10" s7:referencePoint="inherit" s7:rowCount="1" s7:rowGap="18" s7:rowMajorOrder="true" s7:stroke="false" s7:strokeOverprint="false" s7:warpBend="0.5" s7:warpDirection="horizontal" s7:warpHorizontalDistortion="0" s7:warpStyle="none" s7:warpVerticalDistortion="0" s7:weight="1" ai:aa="2" ATE:C_charRotation="0" ATE:C_horizontalScale="1" ATE:C_kerning="metric" ATE:C_verticalScale="1" ATE:P_autoHyphenate="true" ATE:P_consecutiveHyphenLimit="0" ATE:P_hyphenateCapitalized="true" ATE:P_hyphenatedWordSize="6" ATE:P_hyphenationPreference="0.5" ATE:P_hyphenationZone="36" ATE:P_postHyphenSize="2" ATE:P_preHyphenSize="2" d:userLabel="id:line1">
   <content><p><span>Address Line 1</span></p></content>
</RichText>

XML ファイルには、同様の構造を持つノードが多数あります。ただし、この場合、各RichTextノードには一意の要素 ID があります。s7:elementID="line1"

PHP または JavaScript を使用して、次のいずれかを取得するにはどうすればよいですか。

  1. テキスト「住所 1」
  2. content、p、span タグを含む行全体

指定した場合elementID、コンテンツの取得先は?

私は XML にあまり詳しくないので、これが可能かどうかはわかりません。

4

1 に答える 1

1

以下を使用して、xml をオブジェクトにロードします。simplexml_load_string()

次に->xpath('RichText')、そのオブジェクトで使用して RichText 要素を取得します。

->asXML()これらの要素で使用すると、

あなたが得る"<content><p><span>Address Line 1</span></p></content>"

いつも"<content><p><span>"ですか?

その後、使用できます(string) $RichText->content[0]->p[0]->span[0]

于 2012-06-26T21:41:50.717 に答える