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

  • Home
  • SEARCH
  • 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 6959929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:20:14+00:00 2026-05-27T15:20:14+00:00

i want to use XML to save some configuration for elements in my app.

  • 0

i want to use XML to save some configuration for elements in my app.
in my example i want to add 6 additional configuration sets to one “main” XML. each set can be config1 or config2.
In this case i added 3x config1 and 3x config2. if i trace my results i do not only get the wrong order of elements but also some “strange” binding behavior.
Of course this is a simplified example. my configuration sets are more complex (this is why i use seperate xml-objects for each config).

Can someone tell me how this is supposed to work ?

thanks,
quadword

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160" creationComplete="init();">

<fx:Declarations>
    <fx:XML id="mainConfig" format="e4x">
        <allConfigSets>
            <viewconfig>Baseconfig</viewconfig>
        </allConfigSets>
    </fx:XML>

    <fx:XML id="configSet1" format="e4x">
        <configSet><viewconfig>Set1</viewconfig></configSet>
    </fx:XML>

    <fx:XML id="configSet2" format="e4x">
        <configSet><viewconfig>Set2</viewconfig></configSet>
    </fx:XML>
</fx:Declarations>

<fx:Script>
    <![CDATA[
        private function init(): void {     

            mainConfig.appendChild(configSet1.viewconfig);
            mainConfig.appendChild(configSet1.viewconfig);
            mainConfig.appendChild(configSet1.viewconfig);
            mainConfig.appendChild(configSet2.viewconfig);
            mainConfig.appendChild(configSet2.viewconfig);
            mainConfig.appendChild(configSet2.viewconfig);

            // trace1 (see below): trace shows wrong order of elements
            trace (mainConfig);

            // trace2:(see below): changing data on original configSet seems to bind into mainConfig
            configSet1.viewconfig = "-";
            trace (mainConfig);
        }
    ]]>
</fx:Script>
</s:Application>

Trace1:
<allConfigSets>
  <viewconfig>Baseconfig</viewconfig>
  <viewconfig>Set1</viewconfig>
  <viewconfig>Set2</viewconfig>
  <viewconfig>Set2</viewconfig>
  <viewconfig>Set2</viewconfig>
  <viewconfig>Set1</viewconfig>
  <viewconfig>Set1</viewconfig>
</allConfigSets>

Trace2:
<allConfigSets>
  <viewconfig>Baseconfig</viewconfig>
  <viewconfig>-</viewconfig>
  <viewconfig>Set2</viewconfig>
  <viewconfig>Set2</viewconfig>
  <viewconfig>Set2</viewconfig>
  <viewconfig>-</viewconfig>
  <viewconfig>-</viewconfig>
</allConfigSets>

Using AS3 XML Objects does not solve this issue:

private function init(): void {     
    var mainConfig:XML = <allConfigSets><viewconfig>0</viewconfig></allConfigSets>
    var configSet1:XML = <configSet><viewconfig>1</viewconfig></configSet>
    var configSet2:XML = <configSet><viewconfig>2</viewconfig></configSet>

    mainConfig.appendChild(configSet1.viewconfig);
    mainConfig.appendChild(configSet1.viewconfig);
    mainConfig.appendChild(configSet1.viewconfig);

    mainConfig.appendChild(configSet2.viewconfig);
    mainConfig.appendChild(configSet2.viewconfig);
    mainConfig.appendChild(configSet2.viewconfig);

    // trace1 (see below): trace shows wrong order of elements
    trace (mainConfig);

    // trace2:(see below): changing data on original configSet seems to bind into mainConfig
    configSet1.viewconfig = "-";
    trace (mainConfig);
}

Trace1:
<allConfigSets>
  <viewconfig>0</viewconfig>
  <viewconfig>1</viewconfig>
  <viewconfig>2</viewconfig>
  <viewconfig>2</viewconfig>
  <viewconfig>2</viewconfig>
  <viewconfig>1</viewconfig>
  <viewconfig>1</viewconfig>
</allConfigSets>

Trace2:
<allConfigSets>
  <viewconfig>0</viewconfig>
  <viewconfig>-</viewconfig>
  <viewconfig>2</viewconfig>
  <viewconfig>2</viewconfig>
  <viewconfig>2</viewconfig>
  <viewconfig>-</viewconfig>
  <viewconfig>-</viewconfig>
</allConfigSets>
  • 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-05-27T15:20:14+00:00Added an answer on May 27, 2026 at 3:20 pm

    The simultaneous change happens, because you keep appending multiple references to the exact same node (instead of new nodes).

    Think of it this way (pseudo code!):

    <node1>value</node1>
    
    <node2>
        <reference>Go, look at node1!</reference>
        <reference>Go, look at node1!</reference>
        <reference>Go, look at node1!</reference>
    </node2>
    

    Whenever a reference is encountered, the value stored in node1 is returned. When you change that original value, since all the references point to the same node, they will also return the same new value.

    To append new copies of your nodes instead of the original, use

    mainConfig.appendChild(configSet1.viewconfig.copy());
    

    but keep in mind that copy() returns a copy of the entire subtree of the node, not just the node itself.

    As to why the order of elements is wrong, I am really at a loss – XML#appendChild() should add the elements to the end of the list of child nodes. Does trace (mainConfig.toXMLString()); return the same result?

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

Sidebar

Related Questions

I have an XML document with un-namespaced elements, and I want to use XSLT
I want to create a file t save some information for my app next
I want to use XML for UI layout and element definition. Want them to
I would like to create an XML-based website. I want to use XML files
I want to use the default XML editor (org.eclipse.wst.xml.ui) of Eclipse in an RCP
I want to use data binding with an XML document to populate a simple
I want to use either a DTD or an XSD to describe my XML
I want to use javascript / jquery to determine if an xml file exists.
I have a string in XML format and I want to use this string
HI, I want to use FOP to prepare a XML document for printing (ps/pdf).

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.