Help - Kind of got it all working ...but kind of not :)

  • playboxdesign
  • Born
  • Born
  • User avatar
  • Posts: 3
  • Loc: UK

Post 3+ Months Ago

This is my code (it looks rather strange but partially works) :

Code: [ Select ]
UnitdataXML = new XML();
UnitdataXML.ignoreWhite = true;

UnitdataXML.onLoad = myLoad;
UnitdataXML.load("Moodle.xml");

function myLoad(ok) {
    if (ok == true) {
        Publish(this.firstChild);
    }
}

function Publish(UnitdataXMLNode) {
    if (UnitdataXMLNode.nodeName.toUpperCase() == "UNIT") {
        content = "";

        unit_info = UnitdataXMLNode.firstChild;


        while (unit_info != null) {
            if (unit_info.nodeName.toUpperCase() == "UNIT_INFO") {
                uno = "";
                uname = "";
                loutcomes = "";
                pass = "";
                merit = "";
                distinction = "";
            }
            element = unit_info.firstChild;
            //////////////////////////////////////////////////////////////////////////


            while (element != null) {
                if (element.nodeName.toUpperCase() == "UNO") {
                    uno = element.firstChild.nodeValue;
                }
                if (element.nodeName.toUpperCase() == "UNAME") {
                    uname = element.firstChild.nodeValue;
                }
                if (element.nodeName.toUpperCase() == "LOUTCOMES") {
                    loutcomes = element.firstChild.nodeValue;
                }
                if (element.nodeName.toUpperCase() == "PASS") {
                    pass = element.firstChild.nodeValue;
                }
                if (element.nodeName.toUpperCase() == "MERIT") {
                    merit = element.firstChild.nodeValue;
                }
                if (element.nodeName.toUpperCase() == "DISTINCTION") {
                    distinction = element.firstChild.nodeValue;
                }
                element = element.nextSibling;
            }
            unit_info = unit_info.nextSibling;
            //////////////////////////////////////////////////////////////////////
        }
        unitH_txt.htmlText = "<font size='18' color='#00CC00'>"+uno+"</font>";
        unitT_txt.htmlText = "<font size='16'>"+uname+"</font>";


        loutcomes = UnitdataXMLNode.firstChild.childNodes[2].childNodes;
        //trace(loutcomes.length)
        for (i=0; i<loutcomes.length; i++) {
            var num = i+1;
            var info = UnitdataXMLNode.firstChild.childNodes[2].childNodes[i].firstChild.nodeValue;
            Mix += "<LI>"+info+"</LI>";
            //trace("LO"+num+" = "+info+".");
        }
        pass = UnitdataXMLNode.firstChild.childNodes[3].childNodes;
        //trace (pass.length);
        for (j=0; j<pass.length; j++) {
            var num = j+1;
            var info2 = UnitdataXMLNode.firstChild.childNodes[3].childNodes[j].firstChild.nodeValue;
            passInfo += "<LI>"+info2+"</LI>";
            //trace ("P"+num+" = "+info2+".")
        }
        merit = UnitdataXMLNode.firstChild.childNodes[4].childNodes;
        for (k=0; k<merit.length; k++) {
            var num = k+1;
            var info3 = UnitdataXMLNode.firstChild.childNodes[4].childNodes[k].firstChild.nodeValue;
            meritInfo += "<LI>"+info3+"</LI>";
        }
        dist = UnitdataXMLNode.firstChild.childNodes[5].childNodes;
        for (l=0; l<dist.length; l++) {
            var num = l+1;
            var info4 = UnitdataXMLNode.firstChild.childNodes[5].childNodes[l].firstChild.nodeValue;
            distInfo += "<LI>"+info4+"</LI>";
        }
        LO = "<font size='12'><UL>"+Mix+"</UL></font>";
        l1_txt.htmlText = LO;

    }
}
  1. UnitdataXML = new XML();
  2. UnitdataXML.ignoreWhite = true;
  3. UnitdataXML.onLoad = myLoad;
  4. UnitdataXML.load("Moodle.xml");
  5. function myLoad(ok) {
  6.     if (ok == true) {
  7.         Publish(this.firstChild);
  8.     }
  9. }
  10. function Publish(UnitdataXMLNode) {
  11.     if (UnitdataXMLNode.nodeName.toUpperCase() == "UNIT") {
  12.         content = "";
  13.         unit_info = UnitdataXMLNode.firstChild;
  14.         while (unit_info != null) {
  15.             if (unit_info.nodeName.toUpperCase() == "UNIT_INFO") {
  16.                 uno = "";
  17.                 uname = "";
  18.                 loutcomes = "";
  19.                 pass = "";
  20.                 merit = "";
  21.                 distinction = "";
  22.             }
  23.             element = unit_info.firstChild;
  24.             //////////////////////////////////////////////////////////////////////////
  25.             while (element != null) {
  26.                 if (element.nodeName.toUpperCase() == "UNO") {
  27.                     uno = element.firstChild.nodeValue;
  28.                 }
  29.                 if (element.nodeName.toUpperCase() == "UNAME") {
  30.                     uname = element.firstChild.nodeValue;
  31.                 }
  32.                 if (element.nodeName.toUpperCase() == "LOUTCOMES") {
  33.                     loutcomes = element.firstChild.nodeValue;
  34.                 }
  35.                 if (element.nodeName.toUpperCase() == "PASS") {
  36.                     pass = element.firstChild.nodeValue;
  37.                 }
  38.                 if (element.nodeName.toUpperCase() == "MERIT") {
  39.                     merit = element.firstChild.nodeValue;
  40.                 }
  41.                 if (element.nodeName.toUpperCase() == "DISTINCTION") {
  42.                     distinction = element.firstChild.nodeValue;
  43.                 }
  44.                 element = element.nextSibling;
  45.             }
  46.             unit_info = unit_info.nextSibling;
  47.             //////////////////////////////////////////////////////////////////////
  48.         }
  49.         unitH_txt.htmlText = "<font size='18' color='#00CC00'>"+uno+"</font>";
  50.         unitT_txt.htmlText = "<font size='16'>"+uname+"</font>";
  51.         loutcomes = UnitdataXMLNode.firstChild.childNodes[2].childNodes;
  52.         //trace(loutcomes.length)
  53.         for (i=0; i<loutcomes.length; i++) {
  54.             var num = i+1;
  55.             var info = UnitdataXMLNode.firstChild.childNodes[2].childNodes[i].firstChild.nodeValue;
  56.             Mix += "<LI>"+info+"</LI>";
  57.             //trace("LO"+num+" = "+info+".");
  58.         }
  59.         pass = UnitdataXMLNode.firstChild.childNodes[3].childNodes;
  60.         //trace (pass.length);
  61.         for (j=0; j<pass.length; j++) {
  62.             var num = j+1;
  63.             var info2 = UnitdataXMLNode.firstChild.childNodes[3].childNodes[j].firstChild.nodeValue;
  64.             passInfo += "<LI>"+info2+"</LI>";
  65.             //trace ("P"+num+" = "+info2+".")
  66.         }
  67.         merit = UnitdataXMLNode.firstChild.childNodes[4].childNodes;
  68.         for (k=0; k<merit.length; k++) {
  69.             var num = k+1;
  70.             var info3 = UnitdataXMLNode.firstChild.childNodes[4].childNodes[k].firstChild.nodeValue;
  71.             meritInfo += "<LI>"+info3+"</LI>";
  72.         }
  73.         dist = UnitdataXMLNode.firstChild.childNodes[5].childNodes;
  74.         for (l=0; l<dist.length; l++) {
  75.             var num = l+1;
  76.             var info4 = UnitdataXMLNode.firstChild.childNodes[5].childNodes[l].firstChild.nodeValue;
  77.             distInfo += "<LI>"+info4+"</LI>";
  78.         }
  79.         LO = "<font size='12'><UL>"+Mix+"</UL></font>";
  80.         l1_txt.htmlText = LO;
  81.     }
  82. }


and my XML:

Code: [ Select ]
<UNIT>
 <UNIT__INFO>
  <UNO>Unit 8:</UNO>
  <UNAME>Design and Principles in Art and Design</UNAME>
  <LOUTCOMES>
   <LO1>Understand how form relates to function in their own work</LO1>
   <LO2>Be able to use appropriate materials in own work</LO2>
   <LO3>Know how cultural associations affect their own work</LO3>
   <LO4>Understand design for need and the repsonsibilities of designners</LO4>
  </LOUTCOMES>
  <PASS>
   <P1>Explain how form relates to function in their own work</P1>
   <P2>Use appropriate materials in their own design work</P2>
   <P3>Explain how cultural associations affect their own work</P3>
   <P4>Explain design for need and the responsibilities of the designer</P4>
  </PASS>
  <MERIT>
   <M1>Demonstrate skills and understanding in applying aesthetic considerations to functional requirements in their finished design work</M1>
   <M2>Show an effective and considered understanding of applying design principles when producing their own work</M2>
  </MERIT>
  <DISTINCTION>
   <D1>Show an independent approach to research and the application of innovative design ideas.</D1>
   <D2>Show how the evaluation undertaken in the designs stages has been applied to the development and production of exciting, coherent and individual design work.</D2>
  </DISTINCTION>
 </UNIT_INFO>
</UNIT>
  1. <UNIT>
  2.  <UNIT__INFO>
  3.   <UNO>Unit 8:</UNO>
  4.   <UNAME>Design and Principles in Art and Design</UNAME>
  5.   <LOUTCOMES>
  6.    <LO1>Understand how form relates to function in their own work</LO1>
  7.    <LO2>Be able to use appropriate materials in own work</LO2>
  8.    <LO3>Know how cultural associations affect their own work</LO3>
  9.    <LO4>Understand design for need and the repsonsibilities of designners</LO4>
  10.   </LOUTCOMES>
  11.   <PASS>
  12.    <P1>Explain how form relates to function in their own work</P1>
  13.    <P2>Use appropriate materials in their own design work</P2>
  14.    <P3>Explain how cultural associations affect their own work</P3>
  15.    <P4>Explain design for need and the responsibilities of the designer</P4>
  16.   </PASS>
  17.   <MERIT>
  18.    <M1>Demonstrate skills and understanding in applying aesthetic considerations to functional requirements in their finished design work</M1>
  19.    <M2>Show an effective and considered understanding of applying design principles when producing their own work</M2>
  20.   </MERIT>
  21.   <DISTINCTION>
  22.    <D1>Show an independent approach to research and the application of innovative design ideas.</D1>
  23.    <D2>Show how the evaluation undertaken in the designs stages has been applied to the development and production of exciting, coherent and individual design work.</D2>
  24.   </DISTINCTION>
  25.  </UNIT_INFO>
  26. </UNIT>


Any hints as to what i can do to tidy it up please????
Attachments:
FlaFile.zip

(85.09 KiB) Downloaded 214 times

Attachments:
FlaFile.zip

(85.09 KiB) Downloaded 214 times

  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

what's it supposed to do that it doesn't do?
  • playboxdesign
  • Born
  • Born
  • User avatar
  • Posts: 3
  • Loc: UK

Post 3+ Months Ago

It is the 'undefined' when you press the P M and D buttons. The information comes up but I think it is the main node ie the

Pass node - that is undefined
where as the 4 nodes inside there are ok.

I have kind of hacked together bits of code from a couple of tutorials.

I really did not want it 'hard coded', I wanted to load the xml and loop through the nodes, child nodes and their child nodes using the .length etc

So I want 3 nested loops - but getting myself so confused with the syntax for the nodes. I would like some really tidy non hard coded code. I was going to start off in Pseudo code to try and work it all out from there... kind of lost a bit of steam at moment, it was making my head hurt :)
  • playboxdesign
  • Born
  • Born
  • User avatar
  • Posts: 3
  • Loc: UK

Post 3+ Months Ago

ps. wanted to use 'arrays' just can not work out if I need 3 for the 3 nested loops or what.

Any advise would be much appreciated Graphixboy, thank you

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 11 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.