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

Creating XML object & adding children

Community Expert ,
Dec 10, 2009 Dec 10, 2009

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

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.

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

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

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

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

Chuck

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