Skip to main content
Known Participant
December 4, 2018
Answered

problem forming XML from Array

  • December 4, 2018
  • 2 replies
  • 855 views

problem with xml forming wrong the first example works most the time but often it puts it inside it self, example below in blue. my second way happens all the time where my document title gets put into the xml

XMLdoc.doc.x.setChildren(new XMLList());

XMLdoc.doc.y.setChildren(new XMLList());

for ( r = 0; r < mytextArray.length; r++){

XMLdoc.doc.x.appendChild(

<mystuff>{mytextArray}</mystuff>)

}

<x>

<mystuff>

  <mystuff>.zzzzzzzzzzzzz</mystuff>

</mystuff>

<mystuff>.aaaaaaaaaaaaaaa</mystuff>

</x>

/////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////

XMLdoc.doc.x.setChildren(new XMLList());

XMLdoc.doc.y.setChildren(new XMLList());

for ( r = 0; r < mytextArray.length; r++){

XMLdoc.doc.x.mystuff = mytextArray

}

<x>

      <mystuff xmlns="codesnipp1_8_fla:MainTimeline">.zzzzzzzzzzzzz :Number = new</mystuff>

     <mystuff xmlns="codesnipp1_8_fla:MainTimeline">.aaaaaaaaaaa :Number = new</mystuff>

</x>

    Correct answer ClayUUID

    I am trying to make it so xml can push into an Array and an Array can push back into the xml.  I am doing this because I aleady have a bunch of code with Arrays, but I could switch it all to xml and skip the arrays altogether and I probably could get it to work but I figured it would be easy to push the Array into the XML and vice versa.  I need the XML for saving purposes.

    also what type of variable represents a singular xml object if I don't want it to be a string

    maybe if I push the variable and not the xml chain it might not get the tags too.  Just a thought


    olinh26627966  wrote

    ...but I could switch it all to xml and skip the arrays altogether...

    For the love of god, no. The entire purpose of XML is as a generic data interchange format. It should never, ever be used as a working data structure.

    2 replies

    Known Participant
    December 4, 2018

    I got it.  I was wrong about not having a string variable.  The error I was having the first time I tried must of been unrelated to my string variable. So the solution was definitely putting the XML into variable form first and not putting XML directly into the Array.  I don't know why it would be this way. Sloppy code maybe, I don't know, or maybe its just the way it should be. 

    kglad
    Braniac
    December 4, 2018

    use the trace function to debug. eg:

    for ( r = 0; r < mytextArray.length; r++){

    XMLdoc.doc.x.appendChild(

    <mystuff>{mytextArray}</mystuff>)

    trace(r,":",{mytextArray},":",mystuff>{mytextArray}</mystuff>)

    }

    Known Participant
    December 4, 2018

    I see it is in the Array so this is where I push it in maybe here

    myxmlload2()

    mytextArray.length = 0

    colorArray.length = 0

    for ( i = 0; i < XMLdoc.doc.x.children().length(); i++){

    //var st1:init = XMLdoc.doc.y.mystuff

    mytextArray.push(XMLdoc.doc.x.mystuff)

    }

    kglad
    Braniac
    December 4, 2018

    your code looks like a convoluted mess but if it works for you, that's great.