原帖见:
http://community.csdn.net/Expert/topic/4581/4581031.xml?temp=.7869837

解决方案 »

  1.   

    上一个帖子中,你说为什么为2,是吧?-----------------------------------------------------------------------
    刚试了一下,x.childNodes[0].childNodes.length为1,应该是2才对的.
    为什么?
    ------------------------------------------------------------------------我觉得很可能是你的xml编辑时不是用标准的XML编辑器编辑的,里面有回车之类的东西,我在JAVA中用dom时候遇到过这个问题,不知道JS有没有这个问题,我想应该是差不多的。比方说你的那个xml,x.childNodes[0].childNodes.length,很可能是<NewDataSet>这个后面有一个空格或者回车,这样x.childNodes[0]就是指那个特殊字符的对象,而不是指第一个<table>标签。在childNodes.length就是指空格文本,这个只有一个文本对象,所以length是1
    <?xml version="1.0" encoding="GB2312"?>
    <NewDataSet>空格
    <table>
          <id>80</id>
            <customerno>0001</customerno>
            <customername>寶來電業廠</customername>
            <shortname>寶來</shortname>
            <address>test</address>
          </Table>
          <Table>
            <id>81</id>
            <customerno>0002</customerno>
            <customername>照明股伀有限公司</customername>
            <shortname>照明</shortname>
            <address>rwar</address>
          </Table>
        </NewDataSet>