A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Adding node to XMLList

  1. #1
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90

    Adding node to XMLList

    I have the following 'myXML' XML object:

    Code:
    <layout>
    <region id="main" left="295" width="458" top="35" height="343"/> 
    <region id="subs" left="265" width="520" top="440" height="50" />
    <region id="links" left="45" width="150" top="70" height="180" />
    <region id="video" left="48" width="160" top="330" height="125" />
    <region id="links-down" left="45" width="150" top="165" height="95"/>
    <region id="links-small" left="45" width="150" top="60" height="100"/>
    </layout>
    and '<region>' nodes loaded inside a XMLList object called 'xml_list':

    Code:
    var xml_list:XMLList = new XMLList(myXML.region);
    and i would like to add for example this node to that XMLList:

    Code:
    <region id="test" left="0" width="0" top="0" height="0"/>
    How can i accomplish that?

    thanks in advance,
    best regards

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    myXML is the XML object:

    myXML.region.(@id=="links-small").appendChild('<region id="test" left="0" width="0" top="0" height="0"/>');
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    Thank you, i though there was maybe something similar to 'appendChild' method but for XMLList object.

    best regards

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Then you need to write in that way.

    var xml_list:XMLList = new XMLList(myXML.region.(@id=="links-small"));
    xml_list.appendChild('<region id="test" left="0" width="0" top="0" height="0"/>');

    Only one list item is allowed.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    Quote Originally Posted by cancerinform
    Only one list item is allowed.
    That was the problem i obviously had, thanks for explanation.

    cheers

  6. #6
    Databarnak atRax's Avatar
    Join Date
    Dec 2000
    Location
    Zurich, Switzerland
    Posts
    258
    If I am right XMLList doesn't have the same methods as XML therefore you cant appendChild but XMLList acts just like XML in term of how it handle ecma.

    but I haven't try appendChild on a Xlist before... maybe it works
    I ask you all to concentrate really hard on the freedom of all being. Its hard not to be very angry it is impossible We have to focus this confusion frustration helplessness feeling into a creative outlet Anger can spawn such amazing creativity through Street art Free art to teach each other know each other a language our evolution Go ahead and break some dumb rules

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    An XMLList object with one element is treated like an XML object and all the methods as for the XML object apply but not when there are more than one element in the XMLList object.
    - The right of the People to create Flash movies shall not be infringed. -

  8. #8
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    I tried that but it didn't work, that's why i thought that maybe there is a similar method but for XMLList. Thanks for everything cancerinform

    cheers

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Quote Originally Posted by blu3
    I tried that but it didn't work, that's why i thought that maybe there is a similar method but for XMLList.
    var xml_list:XMLList = new XMLList(myXML.region);

    This is not one element but several elements.
    - The right of the People to create Flash movies shall not be infringed. -

  10. #10
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    That's where i made a mistake i guess, didn't realize it. Everyhing should work fine now.

    When it comes to xml, i have one more question if it's not too much to ask. I am trying to check wheater 'test' node contains 'xmlns' attribute or not. I tried with:

    Code:
    var xml:XML = new XML (<test xmlns="http://www.test.com">
                                  </test>);
    
    if (xml.attribute("id") == null){
      trace("Attribute doesn't exist...");
    }else{
      trace ("Attribute exists...");
    }
    But i get 'Attribute exists' wheather it really exists or not, and if i rename 'xmlns' attribute to something else than it works I understand that 'xmlns' is special attribute but still, how can i check wheather it exists in node or not?

    thanks,
    best regards

  11. #11
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    if (xml.attribute("id")==undefined)

    In your example xmlns is not recognized as an attribute but as a namespace declaration (xml.namespaceDeclarations()). You need to be careful there.
    - The right of the People to create Flash movies shall not be infringed. -

  12. #12
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    Quote Originally Posted by cancerinform
    if (xml.attribute("id")==undefined)

    In your example xmlns is not recognized as an attribute but as a namespace declaration (xml.namespaceDeclarations()). You need to be careful there.
    I see, but that's in fact what i need to do - check wheather 'xmlns' (i posted 'id' attribute as an exmaple thinking that it's the same whatever attibute i check which obviously isn't true) namspace declaration exists or not and usual mehods don't work

  13. #13
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to write it this way if you are looking for xmlns specifically:

    PHP Code:
    var xml:XML = new XML (<test xmlns="yoursite.com" test="mysite.com">
                                  </
    test>);

    if (
    xml.namespaceDeclarations() == "")
    {
        
    trace ("nsd doesn't exist...");
    }
    else
    {
        
    trace ("nsd exists...");
    }
    if (
    xml.attribute("id") == undefined)
    {
        
    trace ("Attribute doesn't exist...");
    }
    else
    {
        
    trace ("Attribute exists...");

    - The right of the People to create Flash movies shall not be infringed. -

  14. #14
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    I get it now, thanks a lot for everything cancerinform. I really appreciate it.

    cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center