1 Reply Latest reply on Oct 20, 2009 3:09 AM by Revlex

    XML depth chek parent, children, grandchildren, great-grandchildren

    Revlex

      Hi there,

       

      Iv'e been scouting the internet for a while now and i cant find the solution im searching for.

      The question where i have searched the inetnet for is: Is there a way to chek how deep goes a XML file.

       

      If someone can point me in the right direction ill be verry verry happy.

      The main idea behind the question is a bit difficult here some explanation.


      I'm going to get different types of XML file's wich are completely random built by different friends who send the XML file's. There's one good thing about it tough, a friend send's always the same XML file with the same build up. This come in handy so i can use a own generated .txt file to go trough the structure of a particular friend.

       

      The some_file.txt is build in hierarchical order.

       

      I'm sorry if the code's get a little bit verry big..................

       

      This is how far i dit get with the code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="400" minHeight="300" width="400" height="300">
      <fx:Script>
          <![CDATA[
              import flash.net.*;
             
              import mx.controls.*;
             
              private var xml_loader:URLLoader = new URLLoader();
              private var txt_loader:URLLoader = new URLLoader();
              private var element_arr:Array = new Array();
              private var processed_data:Array = new Array();
             
              private function init_vars(evt:Event):void
              {
                  var naam_bedrijf:String = bedrijf_naam.text + ".txt";
                  var uri_xml:String = xml_url.text;
                  txt_loader.load(new URLRequest(naam_bedrijf));
                  xml_loader.load(new URLRequest(uri_xml));
                  xml_loader.addEventListener(Event.COMPLETE, xml_complete);
                  xml_loader.addEventListener(IOErrorEvent.IO_ERROR, xml_error);
                 
                 
              }
             
              private function xml_error(evt:IOErrorEvent):void
              {
                  Alert.show(evt.text ,"Foutmelding");
              }
             
              private function xml_complete(evt:Event):void
              {
                  var txt_string:String = txt_loader.data;
                  var xml:XML = new XML(xml_loader.data);
                  var xml_list:XMLList = new XMLList(xml);
                  element_arr = txt_string.split(",");
                  var i:int = 1;
                  var total_parrent_elements:int = xml_list.child(element_arr[0]).length();
                  xml_list.normalize();
                  while(i <= total_parrent_elements)
                  {
                      var kind:int = 1;
                      var parent_child:int = element_arr.length - 1;
                      while(kind <= parent_child)
                      {
                          processed_data[i][kind] = xml_list.child(element_arr[0])[i].elements(element_arr[kind]).text();                   
                          kind++;
                      }
                      i++;
                  }

          ]]>
      </fx:Script>   
          <s:TextInput x="10" y="8" enabled="true" id="xml_url" text="xml.xml" width="157"/>
          <s:TextInput x="232" y="9" text="azrh" id="bedrijf_naam" enabled="true"/>
          <s:Button x="232" y="61" label="Verwerk data!!!" id="start_verwerk_data" enabled="true" click="init_vars(event)"/>
          <s:TextArea x="82" y="106" id="test_box"/>
      </s:Application>

       

      And this is the xml i currently have from a friend:

       

      <Products>
      <Product>
          <Category>Boilers</Category>
          <SubCategory>Zonneboiler</SubCategory>
          <Brand>Vaillant</Brand>
          <ProductName>Vaillant AuroSTEP VSL S 150 S T 'op dak' montage</ProductName>

       

          <Deeplink>
              http://www.google.nl
          </Deeplink>
          <Price>2092,17</Price>
          <DeliveryPeriod>1-2 dagen</DeliveryPeriod>
          <DeliveryCosts>0</DeliveryCosts>
          <OfferId>01050100</OfferId>
          <ProductVendorPartNr/>
          <ProductEAN/>
          <ProductDescription>Vaillant AuroSTEP VSL S 150 S T 'op dak' montage</ProductDescription>

       

          <DeeplinkPicture>
              http://www.some_site.nl/static/images/product/01050100.jpg
          </DeeplinkPicture>
          <StockStatus/>
          <ProductsInStock/>

       

          <PromotionText>
              Op zoek naar een Vaillant AuroSTEP VSL S 150 S T 'op dak' montage schuindak? Dan zit u goed bij Warmteservice. Voor een vaste lage prijs en online te bestellen!
          </PromotionText>

       

      <Attributes>

       

          <Attribute>
              <Key>duurzaam</Key>
              <Value>Ja</Value>
              <Unit></Unit>
          </Attribute>

      </Attributes>
      </Product>

       

      and this is my own generatet .txt file:

       

      Product,Category,

      SubCategory,Brand,

      ProductName,Deeplink,

      Price,DeliveryPeriod,

      DeliveryCosts,OfferId,

      ProductVendorPartNr,ProductEAN

      ,ProductDescription,DeeplinkPicture,

      StockStatus,PromotionText,

      Attributes,Attribute,Key,Value,Unit