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 9276355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:49:52+00:00 2026-06-18T16:49:52+00:00

I have this xml that works for Flash Encoder: <?xml version=1.0 encoding=UTF-8?> <flashmedialiveencoder_profile> <preset>

  • 0

I have this xml that works for Flash Encoder:

<?xml version="1.0" encoding="UTF-8"?>
<flashmedialiveencoder_profile>
    <preset>
        <name></name>
        <description></description>
    </preset>
    <capture>
        <video>
            <device></device> 
            <crossbar_input>1</crossbar_input>
            <frame_rate>25.00</frame_rate>
            <size>
                <width></width>
                <height></height>
            </size>
        </video>
        <audio>
            <device></device> 
            <crossbar_input>2</crossbar_input>
            <sample_rate></sample_rate>
            <channels>1</channels>
            <input_volume>60</input_volume>
        </audio>
    </capture>
    <encode>
        <video>
            <format>H.264</format>
            <datarate></datarate>
            <outputsize></outputsize>
            <advanced>
                <profile></profile>
                <level></level>
                <keyframe_frequency>5 Seconds</keyframe_frequency>
            </advanced>
            <autoadjust>
                <enable>false</enable>
                <maxbuffersize>1</maxbuffersize>
                <dropframes>
                <enable>false</enable>
                </dropframes>
                <degradequality>
                <enable>false</enable>
                <minvideobitrate></minvideobitrate>
                <preservepfq>false</preservepfq>
                </degradequality>
            </autoadjust>
        </video>
        <audio>
            <format>MP3</format>
            <datarate></datarate>
        </audio>
    </encode>
    <restartinterval>
        <days></days>
        <hours></hours>
        <minutes></minutes>
    </restartinterval>
    <reconnectinterval>
        <attempts></attempts>
        <interval></interval>
    </reconnectinterval>
    <output>
        <rtmp>
        <url></url>
        <backup_url></backup_url>
        <stream></stream>
        </rtmp>
    </output>
    <metadata>
        <entry>
        <key>author</key>
        <value></value>
        </entry>
        <entry>
        <key>copyright</key>
        <value></value>
        </entry>
        <entry>
        <key>description</key>
        <value></value>
        </entry>
        <entry>
        <key>keywords</key>
        <value></value>
        </entry>
        <entry>
        <key>rating</key>
        <value></value>
        </entry>
        <entry>
        <key>title</key>
        <value></value>
        </entry>
    </metadata>
    <preview>
        <video>
        <input>
            <zoom>50%</zoom>
        </input>
        <output>
            <zoom>50%</zoom>
        </output>
        </video>
        <audio></audio>
    </preview>
    <log>
        <level>100</level>
        <directory></directory>
    </log>
</flashmedialiveencoder_profile>

And I need to update some of the data depending on the type of xml the user requires. So I want to do something like this:

$data = array (
    'preset' => array (
        'name' => 'Low Bandwidth (150 Kbps) - H.264',
    ),
    'capture' => array (
        'audio'  => array (
            'sample_rate' => 44100
        )
    ),
    'encode' => array (
        'video' => array (
            'datarate' => '300;',
            'outputsize' => '480x360;',
            'advanced' => array (
                'profile' => 'Main',
                'level' => 2.1,
            )
         ),
         'audio' => array (
            'datarate' => 48
         )
    ),
);

I know this tree works, cause I can do it manually, but the problem is that I don’t want to do it like that, so if in the future I need to change other think in the xml, I have only to add it to the array configuration.

How can I do it? I can write a recursive function to do it, but I don’t really want to do it in that way. Is there any other way to do it? I don’t know… may be something like:

$xml->updateFromArray($data);

As I repeat, I can write that function and extend SimpleXMLElement, but if there is any other native php method to do it, it will be better.

  • 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-18T16:49:54+00:00Added an answer on June 18, 2026 at 4:49 pm

    Considering $xml is the document element as a SimpleXMLElement and $data is your array (as in the question), if you are concerned about numbering children, e.g. for metadata, I have it numbered in the array this way:

    'metadata' => array(
        'entry' => array(
            5 => array(
                'value' => 'Sunny Days',
            ),
        ),
    ),
    

    The following shows how to solve the problem in a non-recursive manner with the help of a stack:

    while (list($set, $node) = array_pop($stack)) {
        if (!is_array($set)) {
            $node[0] = $set;
            continue;
        }
    
        foreach ($set as $element => $value) {
            $parent = $node->$element;
            if ($parent[0] == NULL) {
                throw new Exception(sprintf("Child-Element '%s' not found.", $element));
            }
            $stack[] = array($value, $parent);
        }
    }
    

    Some notes:

    • I changed the concrete exception type to remove the dependency.
    • $parent[0] == NULL tests the element $parent is not empty (compare/see SimpleXML Type Cheatsheet).
    • As the element node is put into the stack to be retrieved later, $node[0] needs to be used to set it after it got fetched from the stack (the numbered element is already in $node (the first one by default), to change it later, the number 0 needs to be used as offset).

    And the Online Demo.


    The example so far does not allow to create new elements if they do not exist so far. To add adding of new elements the exception thrown for nonexisting children:

            if ($parent[0] == NULL) {
                throw new Exception(sprintf("Child-Element '%s' not found.", $element));
            }
    

    needs to be replaced with some code that is adding new children including the first one:

            if ($parent[0] == NULL) {
                if (is_int($element)) {
                    if ($element != $node->count()) {
                        throw new Exception(sprintf("Element Number out of order: %d unfitting for %d elements so far.", $element, $node->count()));
                    }
                    $node[] = '';
                    $parent = $node->$element;
                } else {
                    $parent[0] = $node->addChild($element);
                }
            }
    

    The exception still in is for the case when a new element is added but it’s number is larger than the existing number of elements plus one. e.g. you have got 4 elements and then you “add” the element with the number 6, this won’t work. The value is zero-based and this normally should not be any problem.

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML that goes like this: <?xml version=1.0 encoding=utf-8 ?> <colors> <color
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
Consider this preferences.xml file: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:title=@string/preference_main> <PreferenceScreen android:title=@string/preference_sight android:key=category_sight> <ListPreference
I have this piece of XML that I use in order to create a
What I want to do is this: I have a pom.xml that depends on
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have some XML that is structured like this: <whatson> <productions> <production> <category>Film</category> </production>
I have this code that reads from XML file. It gets five strings (groupId,
I have an xml that goes like this: <Equipment> <ModificationDate> <Data> </Data> </ModificationDate> </Equipment>
I have this test code that just saves an XML file to a folder.

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.