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

Creating XML object & adding children

Community Expert ,
Dec 10, 2009 Dec 10, 2009

Copy link to clipboard

Copied

I'm trying to create an XML object and add children to it.   I can create the object, add one descendant per descendant, but when I try and add more that one child at the same level, they all get placed in the same node.  Here's a little test I did:

var myXML = new XML()

myXML = XML('<rootnode></rootnode>')  //this created the root node fine.

myXML.firstChild[0] = "Dave"  //This creates a child node fine with the contents "Dave"

myXML.firstChild[1] = "Sam"  //This adds Sam to the node Dave is in rather than creating a new child.

myXML.firstChild[0].secondChild = "Betty" // This creates a child node fine under the first child.

myXML.firstChild[1].secondChild = "Betty" //this will generate an error as there is not a second child.

Using insertChildAfter or insertChildBefore or appendChild don't seem to do anything either.

Any ideas on what I'm doing wrong?

TOPICS
Actions and scripting

Views

500

Translate

Translate

Report

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
Adobe
Community Expert ,
Dec 10, 2009 Dec 10, 2009

Copy link to clipboard

Copied

Looks like I have to use:

var newChild = new XML('<firstChild>' + someVar + '</firstChild>')

myXML.appendChild(newChild).

Just seems you should be able to do it using E4X syntax.

Votes

Translate

Translate

Report

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
Advisor ,
Dec 11, 2009 Dec 11, 2009

Copy link to clipboard

Copied

Firefox behaves the way you expect:

<rootnode>
  <firstChild>
       Dave
        <secondChild>Betty</secondChild>
    </firstChild>
    <firstChild>
        Sam
        <secondChild>Betty</secondChild>
    </firstChild>
</rootnode>


I would consider this a bug.

-X

Votes

Translate

Translate

Report

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 11, 2009 Dec 11, 2009

Copy link to clipboard

Copied

LATEST

Thanks, Xbytor.  That's what I was thinking, but I don't know enough about this to say for sure.

Chuck

Votes

Translate

Translate

Report

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