3 Replies Latest reply on Nov 19, 2007 10:46 AM by ntsiii

    Problem accessing child nodes of an XML object

    edzillion
      My code:

      public function parse( event:ResultEvent ):void {
      yearAC = new ArrayCollection;
      yearData = event.result as XML;
      yearList = yearData.Worksheet;
      var yearItem:XML;
      for each (yearItem in yearList)
      {
      ...
      }
      }

      In debugger I can see that yearData is populated:

      yearData = <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" ... >
      <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office" ... >
      <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel" ... >
      <Styles xmlns="urn:schemas-microsoft-com:office:spreadsheet" ... >
      <Worksheet Name="Annual Average __ Exchange rate" ... >
      <Worksheet Name="Annual Average Price data" ... >

      But I can't seem to populate the XMLList yearList :

      yearList = yearData.Worksheet;
      yearList = yearData.Worksheet[1];
      yearList = yearData..Rows;

      ...all return empty XMLLists.

      TIA,
      Ed
        • 1. Re: Problem accessing child nodes of an XML object
          ntsiii Level 3
          The best way to handle issues like this is to approach it a node at a time.

          First, trace the root node as you have done.

          then get a ref to the next node in the path you want, ad trace it, and so forth.

          I can' tell from the xml you posted, but I suspect Worksheet is not a first level child of Workbook.

          Tracy
          • 2. Problem accessing child nodes of an XML object
            edzillion Level 1
            Hmmm,
            I opened the XML file in an external editor to have a look at the node names.
            The watch window shows the node name I am trying to access as Worksheet but the external editor showed it as ss:Worksheet:

            <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" ... >
            ...
            <ss:Worksheet ss:Name="Annual Average __ Exchange rate">
            ...
            </Workbook>

            Can't find anything about referencing nodes with colons in the middle, cannot trace(yearData.ss:Worksheet); or trace(yearData.ss);
            The xml file is an xml export from an excel spreadsheet using openoffice 2.1.

            Cheers
            Ed
            • 3. Re: Problem accessing child nodes of an XML object
              ntsiii Level 3
              This is called a namespace. It adds a level of complexity to accessing the data. Read up on xml namespace (as differentiated from component package namespace).

              I have a simple example on www.cflex.net, Ben Clinkinbeard posted an excellent article on his blog. I am not at a machine with easy access to those urls, but google should find them.

              As I recall, the double colon is used with namespaces:
              yearList = yearData.ss::Worksheet

              Tracy