小女子初来乍到,遇到棘手问题,请各位同胞兄弟帮助。。
Ajax拿到responseText
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Tables Sum="3">
<Table Name="aaa" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Table Name="bbb" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Table Name="ccc" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Tables>
</Response>
通过js代码 把这个字符串转成dom,或者jason 解析出 所有Table节点下的Name值(aaa,bbb,ccc),怎么做??例子也可以
Ajax拿到responseText
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Tables Sum="3">
<Table Name="aaa" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Table Name="bbb" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Table Name="ccc" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Tables>
</Response>
通过js代码 把这个字符串转成dom,或者jason 解析出 所有Table节点下的Name值(aaa,bbb,ccc),怎么做??例子也可以
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Tables Sum="3">
<Table Name="aaa" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Table Name="bbb" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
<Table Name="ccc" type="">
<Field FieldName="gid" DataType="int4" Position="0" />
</Table>
</Tables>
</Response>
</textarea>
<script>var xmlParse = function(str)
{
if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined')
{
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
} if (typeof DOMParser != 'undefined')
{
return (new DOMParser()).parseFromString(str, 'text/xml');
}
return createElement('div', null);
}var xml = document.getElementById( 'txt' ).value;
var doc = xmlParse( xml );
var items = doc.getElementsByTagName( 'Table' );
var names = [];
for( var i = 0; i < items.length; i++ ) {
names.push( items[ i ].getAttribute( 'Name' ) )
}
alert( names.join( ',' ) );</script>