parcours d un fichier xml non logique avec javascript

parcours d un fichier xml non logique avec javascript - XML/XSL - Programmation

Marsh Posté le 27-04-2007 à 14:20:30    

bonjour
 
bon j ai un gros probleme de parcours d un fichier xml en javascript
 
xml file :

Code :
  1. <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE counties SYSTEM "county.dtd">
  2. <counties>
  3.     <aCounty>
  4.         <county>All Ireland</county>
  5.         <TotalPopulation>5602470</TotalPopulation>
  6.         <TotalMale>2767613</TotalMale>
  7.         <TotalFemale>2834857</TotalFemale>
  8.         <PercPropMale>49,4</PercPropMale>
  9.         <PercPropFemale>50,6</PercPropFemale>
  10.         <DependencyRatio>0,5</DependencyRatio>
  11.         <Pop_0_14>1198380</Pop_0_14>
  12.         <Pop_15_24>880108</Pop_15_24>
  13.         <Pop_25_44>1669454</Pop_25_44>
  14.         <Pop_45_65>1195202</Pop_45_65>
  15.         <Pop_65plus>659325</Pop_65plus>
  16.         <PercProp_0_14>21</PercProp_0_14>
  17.         <PercProp_15_24>16</PercProp_15_24>
  18.         <PercProp_25_44>29,8</PercProp_25_44>
  19.         <PercProp_45_64>21,33</PercProp_45_64>
  20.         <PercProp_65plus>11,77</PercProp_65plus>
  21.         <Pop15_16plus>4376985</Pop15_16plus>
  22.         <Married>2112496</Married>
  23.         <Separated>236261</Separated>
  24.         <Single>1740878</Single>
  25.         <PercProp_Married>48,26</PercProp_Married>
  26.         <Perc_Prop_Separated>5,4</Perc_Prop_Separated>
  27.         <Perc_Prop_Single>39,77</Perc_Prop_Single>
  28.         <Pop_Catholic>4200017</Pop_Catholic>
  29.         <Perc_Prop_Catholic>74,97</Perc_Prop_Catholic>
  30.         <Pop_NonCatholic>1139234</Pop_NonCatholic>
  31.         <Perc_Prop_NonCatholic>20,33</Perc_Prop_NonCatholic>
  32.         <Pop_NoneNotStated>263274</Pop_NoneNotStated>
  33.         <Perc_Prop_NoneNotStated>4,7</Perc_Prop_NoneNotStated>
  34.         <TotalHHlds>1914683</TotalHHlds>
  35.         <OnePersHhlds>449146</OnePersHhlds>
  36.         <PP_OnePersHhlds>23,46</PP_OnePersHhlds>
  37.         <MarriedCoupleHholds_NoChildren>327306</MarriedCoupleHholds_NoChildren>
  38.         <PP_MarriedCoupleHholds_NoChild>17,09</PP_MarriedCoupleHholds_NoChild>
  39.         <MarriedCoupleHholds_Children>614501</MarriedCoupleHholds_Children>
  40.         <PP_MarriedCoupleHholds_Childre>32,09</PP_MarriedCoupleHholds_Childre>
  41.         <CohabitingcoupleHholds_NoChild>56057</CohabitingcoupleHholds_NoChild>
  42.         <PP_CohabitingcoupleHholds_NoCh>2,93</PP_CohabitingcoupleHholds_NoCh>
  43.         <CohabitingCouple_Children>37087</CohabitingCouple_Children>
  44.         <PP_CohabitingCouple_Children>1,94</PP_CohabitingCouple_Children>
  45.         <LoneParentHholds_Children>181832</LoneParentHholds_Children>
  46.         <PP_LoneParentHholds_Children>9,5</PP_LoneParentHholds_Children>
  47.         <AllHholds>1847081</AllHholds>
  48.         <Households_OO_NoMortgage>645256</Households_OO_NoMortgage>
  49.         <Households_OO_Mortgage>781679</Households_OO_Mortgage>
  50.         <Households_OO>1426935</Households_OO>
  51.         <HouseholdsRented_LA_NIHE_HCOP>221116</HouseholdsRented_LA_NIHE_HCOP>
  52.         <HouseholdsRented_Private>199030</HouseholdsRented_Private>
  53.         <Perc_Hholds_OO>77,25</Perc_Hholds_OO>
  54.         <Perc_Hholds_Rented_LA>11,97</Perc_Hholds_Rented_LA>
  55.         <Perc_Hholds_Rented_P>10,78</Perc_Hholds_Rented_P>
  56.         <TotalHholds>1914732</TotalHholds>
  57.         <PrivateHhold_House_orBungalow>1717159</PrivateHhold_House_orBungalow>
  58.         <Private_Hhold_Flat_Apartment_M>160793</Private_Hhold_Flat_Apartment_M>
  59.         <PrivateHhold_Mobile_TemporaryS>10096</PrivateHhold_Mobile_TemporaryS>
  60.         <PP_PrivateHhold_House_orBungal>89,68</PP_PrivateHhold_House_orBungal>
  61.         <PP_Private_Hhold_Flat_Apartmen>8,4</PP_Private_Hhold_Flat_Apartmen>
  62.         <PP_PrivateHhold_Mobile_Tempora>0,53</PP_PrivateHhold_Mobile_Tempora>
  63.         <Pop_15plus_16plus>3809537</Pop_15plus_16plus>
  64.         <SecondLeveletc>1794823</SecondLeveletc>
  65.         <ThirdLeveletc>834348</ThirdLeveletc>
  66.         <Perc_Second>47,11</Perc_Second>
  67.         <Perc_Third>21,9</Perc_Third>
  68.         <Total15plus_16plus>4276854</Total15plus_16plus>
  69.         <Employed>2303591</Employed>
  70.         <PercProp_Employed>53,86</PercProp_Employed>
  71.         <Unemployed>208444</Unemployed>
  72.         <PercProp_Unemployed>4,87</PercProp_Unemployed>
  73.         <Student>446429</Student>
  74.         <PercProp_Student>10,44</PercProp_Student>
  75.         <Retired>463568</Retired>
  76.         <PercProp_Retired>10,84</PercProp_Retired>
  77.         <LookingafterHome>527193</LookingafterHome>
  78.         <PercProp_Lookingafterhome>12,33</PercProp_Lookingafterhome>
  79.         <Unable_work_disabled>241042</Unable_work_disabled>
  80.         <PercProp_Unable_work_disabled>5,64</PercProp_Unable_work_disabled>
  81.         <AtWork15plus_16plus>2328215</AtWork15plus_16plus>
  82.         <Agriculture_Hunting_Forestry_F>118015</Agriculture_Hunting_Forestry_F>
  83.         <PercProp_AHFF>5,07</PercProp_AHFF>
  84.         <Building_Construction>211022</Building_Construction>
  85.         <PercProp_Building_Construction>9,06</PercProp_Building_Construction>
  86.         <ManufacturingIndustries>366911</ManufacturingIndustries>
  87.         <PercProp_ManufacturingIndustri>15,76</PercProp_ManufacturingIndustri>
  88.         <Commerce>630061</Commerce>
  89.         <PercProp_Commerce>27,06</PercProp_Commerce>
  90.         <Transport>134061</Transport>
  91.         <PercProp_Transport>5,76</PercProp_Transport>
  92.         <PublicAdministration>158771</PublicAdministration>
  93.         <PercProp_PublicAdministration>6,82</PercProp_PublicAdministration>
  94.         <ProfessionalServices>400813</ProfessionalServices>
  95.         <PercProp_ProfessionalServices>17,22</PercProp_ProfessionalServices>
  96.         <Other>308561</Other>
  97.         <PercProp_Other>13,25 </PercProp_Other>
  98.     </aCounty>
  99. </counties>


 
et le javascript qui bug
 

Code :
  1. <script type="text/javascript">
  2.  <![CDATA[
  3.   // load xml file
  4.   function loadXMLFile()
  5.   {
  6.    if (window.ActiveXObject)
  7.    {
  8.     xmlDoc = new ActiveXObject("Microsoft.XMLDOM" );
  9.     xmlDoc.onreadystatechange = function () {
  10.      if (xmlDoc.readyState == 4) createTable()
  11.     };
  12.    }
  13.    else if (document.implementation && document.implementation.createDocument)
  14.    {
  15.     xmlDoc = document.implementation.createDocument("", "", null);
  16.     xmlDoc.onload = createTable;
  17.    }
  18.    else
  19.    {
  20.     alert('Your browser can\'t handle this script');
  21.     return;
  22.    }
  23.    xmlDoc.load("../data/county.xml" );
  24.   }
  25.   function createTable()
  26.   {
  27.    var x = xmlDoc.getElementsByTagName('aCounty');
  28.    alert(x.length); // display 1 =OK  
  29.    alert(x[0].childNodes.length); // display 189 = NOT OK
  30.    alert(x[0].childNodes); // display object node list --> je pense que c est correct
  31.    alert(x[0].childNodes[0]); // display object text --> cela doit correspondre a <aCounty>
  32.    alert(x[0].childNodes[0].nodeValue); // display nothing (viewbox with nothing inside)
  33.    alert(x[0].childNodes[0].nodeValue.length); // display 9 = ?
  34.    alert(x[0].childNodes[0].length); // display 9 = ?
  35.   }
  36.   // display information about county
  37.   var count = 0;
  38.   function displayInformation(evt){
  39.    loadXMLFile();
  40.    svgDocument = evt.target.ownerDocument;
  41.                            var text = svgDocument.getElementById("percent" ).firstChild;
  42.                            text.data = ++count;
  43.   }
  44.  // ]]>
  45. </script>


 
le probleme viendrait de la navigation (bon j ai un probleme avec ie aussi mais tant pis je verrais cela plus tard)
j ai mis des alert un peu partout pour comprendre mais les resultats qu il me sort ne correspondent vraiment a rien du tout.
si quelqu un pouvait m aider je bosse dessus depuis hier et je bloque totalement
merci d avance :hello:


---------------

Reply

Marsh Posté le 27-04-2007 à 14:20:30   

Reply

Marsh Posté le 03-05-2007 à 11:52:22    

après avoir regardé le dom j'ai trouvé la solution :
en fait tous les noeuds sont dupliqués. je me retrouvre avec un noeud normal et un noeud vide (noeud texte).
Bref une petite bizarerie de l'interpréation xml sous firefox d'après ce que j'ai compris.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed