Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

problem forming XML from Array

Community Beginner ,
Dec 03, 2018 Dec 03, 2018

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>

805
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 04, 2018 Dec 04, 2018

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.

Translate
Community Expert ,
Dec 04, 2018 Dec 04, 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>)

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 04, 2018 Dec 04, 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)

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2018 Dec 04, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 04, 2018 Dec 04, 2018

no it doesn't work

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2018 Dec 04, 2018

at the most basic level (ie, without trying to fix the approach you've already started), what are you trying to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 04, 2018 Dec 04, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2018 Dec 04, 2018

what are you using an array for?

what are you using xml for?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2018 Dec 04, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 04, 2018 Dec 04, 2018
LATEST

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines