A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: XML length

  1. #1
    Member
    Join Date
    May 2004
    Posts
    47

    XML length

    Hi
    How can I get the length of <employees> here


    <?xml version="1.0" encoding="iso-8859-1"?>
    <offices>
    <city name="Oslo" offices="7" x="224" y="269" map="test_vektor_by.swf">
    <office name="Kjell B1 Oslo1" map="test_vektor_gate2.swf">
    <vadress>test 1</vadress>
    <vcity>test 1</vcity>
    <phone>22 55 88 24</phone>
    <email>[email protected]</email>
    <employees>
    <employee name="Mette Marit1">
    <title>Daglig og faglig leder Statsaut. eindomsmegler MNEF1</title>
    <phone>37 00 66 55 44</phone>
    <mobile>93 65 48 98</mobile>
    <email>[email protected]</email>
    </employee>
    <employee name="Mette Marit2">
    <title>Daglig og faglig leder Statsaut. eindomsmegler MNEF2</title>
    <phone>37 00 66 55 44</phone>
    <mobile>93 65 48 98</mobile>
    <email>[email protected]</email>
    </employee>
    <employee name="Mette Marit3">
    <title>Daglig og faglig leder Statsaut. eindomsmegler MNEF3</title>
    <phone>37 00 66 55 44</phone>
    <mobile>93 65 48 98</mobile>
    <email>[email protected]</email>
    </employee>
    <employee name="Mette Marit4">
    <title>Daglig og faglig leder Statsaut. eindomsmegler MNEF4</title>
    <phone>37 00 66 55 44</phone>
    <mobile>93 65 48 98</mobile>
    <email>[email protected]</email>
    </employee>
    </employees>
    </office>
    </city>
    </offices>


    thanks in advance

    best regards
    T

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    code:

    var x:XML = new XML();
    x.ignoreWhite = true;
    x.onLoad = function(ok)
    {
    if (ok)
    {
    var temp = this.firstChild.firstChild.firstChild.firstChild.n extSibling.nextSibling.nextSibling.nextSibling.chi ldNodes;
    trace(temp.length);
    }
    };
    x.load("example.xml");



    In these kind of things, it's nice using the debugger.
    Control->Debug Movie
    It will list the variable that holds the loaded xml, and you'll be able to see a tree with all you need to get to where you want.
    There is also the XML forum which may be more appropriate.

  3. #3
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Keep in mind that this technique for reading an XML field (firstChild.firstChild... etc) is very brittle. If the file is formatted slightly differently, the tags reordered, deleted or duplicated, then it will cease to work.

    But if you're confident that the file is always going to contain those tags and exactly those tags, in that order, then go for it!

    There are more robust ways of parsing your XML, typically involving string compares, loops and/or recursive functions.

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