日期:2014-05-16 浏览次数:20440 次
<textarea id="txt" style="display:none;"> <?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>