遍历DOM HTML中的XML

时间:2013-12-21 13:58:56

标签: html xml dom traversal

我的代码有问题

当我点击“获取计划”时,节点的值不会出现

我认为问题不大

我的步骤是正确的

这是xml代码

<?xml version="1.0" encoding="UTF-8"?>

<planner>
   <year value = 2000>

      <date month = "7" day = "15">
         <note id="1" time = "1430">Doctor&apos;s appointment</note>

         <note id="2" time = "1620">Physics class at BH291C</note>

      </date>

      <date month = "7" day = "4">

         <note id="3"> Independence Day</note>

      </date>

      <date month = "7" day = "20">

         <note id="4" time = "0900">General Meeting in room 32-A</note>

      </date>

      <date month = "7" day = "20">

         <note id="5" time = "1900">Party at Joe&apos;s</note>

      </date>

      <date month = "7" day = "20">

         <note time = "1300">Financial Meeting in room 14-C</note>

      </date>

   </year>

</planner>

这是DOM HTML代码

<HTML>
   <HEAD>
       <TITLE>
           Day Planner
       </TITLE>
       <SCRIPT LANGUAGE="JavaScript">
           function readXMLData()

           {

               var xmlDocument, fullparent, partparent, firstparent,
                   firstchild, secondchild, secondparent, childone,
                   thirdparent, childtwo, fourthparent, childthree,
                   fifthparent, childfour;
               var firstvalue, secondvalue, thirdvalue, fourthvalue,
               fifthvalue, sixthvalue;

               xmlDocument = new ActiveXObject( "Microsoft.XMLDOM" );
               xmlDocument.load( "plan.xml" );
               fullparent = xmlDocument.documentElement;

               partparent = fullparent.firstChild;
               firstparent = partparent.firstChild;
               firstchild = firstparent.firstChild;
               secondchild = firstchild.nextSibling;
               secondparent = firstparent.nextSibling;
               childone = secondparent.firstChild;
               thirdparent = secondparent.nextSibling;
               childtwo = thirdparent.firstChild;
               fourthparent = thirdparent.nextSibling;
               childthree = fourthparent.firstChild;
               fifthparent = fourthparent.nextSibling;
               childfour = fifthparent.firstChild;


             displayText = "your tasks is: " +

                    firstchild.firstChild.nodeValue + secondchild.firstChild.nodeValue +
                    childone.firstChild.nodeValue + childtwo.firstChild.nodeValue +
                    childthree.firstChild.nodeValue + childfour.firstChild.nodeValue

                displayDIV.innerHTML = displayText
           }
       </SCRIPT>
   </HEAD>

   <BODY>

        <INPUT TYPE="BUTTON" VALUE="Get Schedule"
           ONCLICK="readXMLData()">
           <DIV ID="displayDIV"></DIV>
        <BR>         
   </BODY>
</HTML>

我的意思是,我想在笔记中显示文字

医生的预约

BH291C的物理课

我想要任何一个测试并告诉我

问题是什么

我希望你帮助我解决它

非常感谢

0 个答案:

没有答案