1 Reply Latest reply on Nov 25, 2006 9:45 AM by peterent

    XML and Flex

    M. Huisman
      Hi,

      Currently i'm developing a component based app in flex which should retrieve it's data from a XML file. But I can't seem to get all the info out, maybe you guys can help me out!

      I've formatted the xml like this:

      <?xml version="1.0" encoding="UTF-8"?>
      <Customer xmlns:p2="http:nl4bintern">
      <Customerid>1</Customerid>
      <Companyname>NL for Business</Companyname>
      <Communicationid>1</Communicationid>
      <Communicationid>3</Communicationid>
      <Communicationid>4</Communicationid>
      <Communicationid>5</Communicationid>
      <Addressid type="Visit">1</Addressid>
      <Addressid type="Postal">2</Addressid>
      </Customer>

      Now I want to get the type of the address using the @ sign, but as soon as I do, I get both id's. is there a better way to check it?

      I'm using this code:

      mx:Script>
      <![CDATA[
      import views.AddressComp;
      public var editmode:Boolean;

      private var customerid:String;


      private function doInit():void {

      /* Static setting of the customerid, normally it would be done in a selection screen before the intialization of this
      perticular application.

      DELETE BEFORE GOING LIFE!!

      */
      customerid = '1';


      if (mdlCustomer.Customerid == customerid) {
      mainPanel.title = mdlCustomer.Companyname;
      if (mdlCustomer.Address.@type == 'Visit') {
      mdlCustomer.Address.filters.tostring();
      visitaddress.setAddressid(mdlCustomer.Addressid);
      visitaddress.getData();
      }
      if (mdlCustomer.Address.@type == 'Postal') {
      contactaddress.contact.setAddressid(mdlCustomer.Addressid);
      }
      }
      editmode = false;
      btnEdit.label = "Edit modus";
      }

      ]]>
      </mx:Script>

      In this code i'm trying to retrieve the data from the xml, and putting it to a component using a function.
        • 1. Re: XML and Flex
          peterent Level 2
          If your XML is loaded into a Flex variable which is an XMLList like this: var demo:XMLList = data.Customer; then demo.Customerid == 1; demo.Companyname == "NL for Business"; demo.Communicationid[0] == 1;

          and demo.Addressid[0].@type == "Visit" and demo.Addressid[1].@type == "Postal"

          should take care of the problem.