Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:48:41+00:00 2026-06-07T01:48:41+00:00

i have the following code that creates two arrays for each RichText element in

  • 0

i have the following code that creates two arrays for each RichText element in my xml source. One of the arrays is for an attribute with a prefix, and the other array is for the attributes that do not have any prefixes. This is the only way I could figure out how to do it:

<?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);

?>

OUTPUT

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
                )

        )

)

My array_merge after the loop creates one huge array, with 4 nested arrays. Two arrays are the default attributes of RichText, and the other two arrays are the attributes that have a s7: prefix. But what I need is that $result and $result1 be merged inside the foreach loop, that way there is just one merged array for each $textNode containing all the attributes. Thus, in this example url I should have two arrays in the end because there are only two RichText elements.

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:48:43+00:00Added an answer on June 7, 2026 at 1:48 am

    This bit of your code:

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

    logically belongs to inside of your foreach loop as I guess you almost knew. However, it does not work there. SimpleXML likes to return SimpleXMLElement objects that can be iterated, but are not arrays themselves, so we need to replace array_merge by something else.

    So all in all:

    $attributesByNode = array();
    
    foreach($textNode as $node) {
        $result1 = $node->attributes('http://ns.adobe.com/S7FXG/2008');
        $result2 = $node->attributes();
    
        foreach ($result1 as $attribName => $attributeValue) 
        { 
            $attributesByNode[$attribName] = $attribVal; 
        } 
        foreach ($result2 as $attribName => $attributeValue) 
        { 
            $attributesByNode[$attribName] = $attribVal; 
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I have the following code that creates a serverside object of the xmlhttp class.
I have the following code that creates the meta-description. I'm getting a 0 as
I have the following code that creates a submenu based on current document. The
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have code using QuickForm that creates a select widget with the following: $form->addElement(
I have the following code that creates a list of dates between a range.
I have the following code, that in my head should create a new row
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code that does not work due to a being a value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.