2

RichText私のxmlソースの各要素に対して2つの配列を作成する次のコードがあります。配列の 1 つは接頭辞を持つ属性用で、もう 1 つの配列は接頭辞を持たない属性用です。これは私がそれを行う方法を理解できる唯一の方法です:

<?php
$url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw";    
$xml = simplexml_load_file($url);       
$xml->registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008');
$xml->registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008');
$textNode = $xml->xpath("//default:RichText[@s7:elementID]");

function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }

$result = array();
$result1 = array();
foreach($textNode as $node){
    $result[] = $node->attributes('http://ns.adobe.com/S7FXG/2008');
    $result1[] = $node->attributes();

}

$text = array_merge($result,$result1);

pr($text);

?>

出力

Array
(
    [0] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [caps] => none
                    [colorName] => 
                    [colorValue] => #518269
                    [colorspace] => rgb
                    [elementID] => smalltext
                    [fill] => true
                    [fillOverprint] => false
                    [firstBaselineOffset] => ascent
                    [joints] => miter
                    [maxFontSize] => 11
                    [miterLimit] => 4
                    [referencePoint] => inherit
                    [rowCount] => 1
                    [rowGap] => 18
                    [rowMajorOrder] => true
                    [stroke] => false
                    [strokeOverprint] => false
                    [warpBend] => 0.5
                    [warpDirection] => horizontal
                    [warpHorizontalDistortion] => 0
                    [warpStyle] => none
                    [warpVerticalDistortion] => 0
                    [weight] => 1
                )

        )

    [1] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [caps] => none
                    [colorName] => 
                    [colorValue] => #518269
                    [colorspace] => rgb
                    [elementID] => largetext
                    [fill] => true
                    [fillOverprint] => false
                    [firstBaselineOffset] => ascent
                    [joints] => miter
                    [maxFontSize] => 19
                    [miterLimit] => 4
                    [referencePoint] => inherit
                    [rowCount] => 1
                    [rowGap] => 18
                    [rowMajorOrder] => true
                    [stroke] => false
                    [strokeOverprint] => false
                    [warpBend] => 0.5
                    [warpDirection] => horizontal
                    [warpHorizontalDistortion] => 0
                    [warpStyle] => none
                    [warpVerticalDistortion] => 0
                    [weight] => 1
                )

        )

    [2] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [x] => 278.418
                    [y] => 115.542
                    [columnGap] => 18
                    [columnCount] => 1
                    [textAlign] => left
                    [fontFamily] => Trade Gothic LT Pro Bold Cn
                    [fontSize] => 11
                    [color] => #518269
                    [whiteSpaceCollapse] => preserve
                    [width] => 212.582
                    [height] => 33
                )

        )

    [3] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [x] => 278.998
                    [y] => 86.7168
                    [columnGap] => 18
                    [columnCount] => 1
                    [textAlign] => left
                    [fontFamily] => Bootstrap
                    [fontSize] => 19
                    [color] => #518269
                    [whiteSpaceCollapse] => preserve
                    [trackingRight] => 4%
                    [width] => 240
                    [height] => 29
                )

        )

)

ループのarray_merge後、4 つのネストされた配列を持つ 1 つの巨大な配列が作成されます。2 つの配列は の既定の属性であり、他の 2 つの配列はプレフィックスRichTextを持つ属性です。s7:しかし、私が必要とし$result$result1いるのは、foreach ループ内でマージされることです。そうすれば$textNode、すべての属性を含むそれぞれのマージされた配列が 1 つだけになります。RichTextしたがって、この例の url では、要素が 2 つしかないため、最後に 2 つの配列が必要です。

これは可能ですか?

4

1 に答える 1