xml vs arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike

    #1

    xml vs arrays

    I have a web document created by a script and instead of going back to
    the db I choose to either create an array to iterate through or xml to
    parse through.

    So, my question is: What are the trade offs between using an array to
    load data from or an xml structure?

    My array would look like:

    myarray = [[],[],[],[]]

    My xml like:

    <xml>
    <data>
    <a></a><b></b>
    </data>
    </xml>

    I would use js to iterate or getElementByTag Name to find data.

    I am thinking the page would load faster using xml, and then the user
    may not even use that functionality. In all cases I have to load the
    array to memory.

    Thoughts?

  • Zifud

    #2
    Re: xml vs arrays

    mike wrote:[color=blue]
    > I have a web document created by a script and instead of going back to
    > the db I choose to either create an array to iterate through or xml to
    > parse through.
    >
    > So, my question is: What are the trade offs between using an array to
    > load data from or an xml structure?
    >
    > My array would look like:
    >
    > myarray = [[],[],[],[]][/color]

    Wouldn't that be an object?
    [color=blue]
    >
    > My xml like:
    >
    > <xml>
    > <data>
    > <a></a><b></b>
    > </data>
    > </xml>
    >
    > I would use js to iterate or getElementByTag Name to find data.
    >
    > I am thinking the page would load faster using xml, and then the user[/color]

    How? Data transmitted as an XML file would likely be 2 to 10 times
    bigger than the same data as an array/object in a JavaScript file,
    significantly affecting load times over the Internet (but perhaps not
    so much over intranet).

    I would also expect any methods on the array/object to be faster than
    using getElement... methods with the same data as an XML document
    (though that is untested and may be dependent on the data structure).
    [color=blue]
    > may not even use that functionality. In all cases I have to load the
    > array to memory.
    >[/color]

    An array/object is loaded without effort, I doubt that would be
    slower than loading than parsing an XML file.
    [color=blue]
    > Thoughts?
    >[/color]

    XML is primarily for the exchange of data where the overhead of
    creating the structure, transmitting it, then parsing it at the other
    end is outweighed by the increased efficiency of standard data
    formats. It is very inefficient for nearly any other purpose.

    --
    Zif

    Comment

    • Dietmar Meier

      #3
      Re: xml vs arrays

      Zifud wrote:
      [color=blue][color=green]
      >> myarray = [[],[],[],[]][/color][/color]
      [color=blue]
      > Wouldn't that be an object?[/color]

      That's an array owning a property "length" of value "4".
      Each of the array's elements is an (empty) array.

      Of course every array is an object, too (typeof myarray
      would result in "object" as for every array).

      ciao, dhgm

      Comment

      • Douglas Crockford

        #4
        Re: xml vs arrays

        mike wrote:[color=blue]
        > I have a web document created by a script and instead of going back to
        > the db I choose to either create an array to iterate through or xml to
        > parse through.
        >
        > So, my question is: What are the trade offs between using an array to
        > load data from or an xml structure?
        >
        > My array would look like:
        >
        > myarray = [[],[],[],[]]
        >
        > My xml like:
        >
        > <xml>
        > <data>
        > <a></a><b></b>
        > </data>
        > </xml>
        >
        > I would use js to iterate or getElementByTag Name to find data.
        >
        > I am thinking the page would load faster using xml, and then the user
        > may not even use that functionality. In all cases I have to load the
        > array to memory.
        >
        > Thoughts?[/color]

        You should be using JSON. It will be much faster than XML.


        Comment

        • mike

          #5
          Re: xml vs arrays

          The xml is embedded in the page already, another file does not have to
          be read. It is an xml structure contained in the page.

          So, what you are saying is that parsing through an array is much faster
          than iterating an xml structure.

          What if we used a xsl stylesheet and did a transformation?

          Comment

          • Lee

            #6
            Re: xml vs arrays

            mike said:[color=blue]
            >
            >The xml is embedded in the page already, another file does not have to
            >be read. It is an xml structure contained in the page.
            >
            >So, what you are saying is that parsing through an array is much faster
            >than iterating an xml structure.
            >
            >What if we used a xsl stylesheet and did a transformation?[/color]

            In that case, the array would be *much* faster.
            You're not going to get faster than the native array or object
            literal notation.

            Comment

            Working...