import { Utils } from "laya/utils/Utils" ; export class Network_XML { constructor ( ) { this . setup ( ) ; } private setup ( ) { var xmlValueContainsError = "<root><item>item a</item><item>item b</item>somethis...</root1>" ; var xmlValue = "<root><item>item a</item><item>item b</item>somethings...</root>" ; this . proessXML ( xmlValueContainsError ) ; console . log ( "\n" ) ; this . proessXML ( xmlValue ) ; } private proessXML ( source ) { try { var xml = Utils . parseXMLFromString ( source ) ; } catch ( e ) { console . log ( e . massage ) ; return ; } this . printDirectChildren ( xml ) ; } private printDirectChildren ( xml ) { var rootNode = xml . firstChild ; var nodes = rootNode . childNodes ; for ( var i = 0 ; i < nodes . length ; i ++ ) { var node = nodes [ i ] ; if ( node . nodeType == 1 ) { console . log ( "节点名称: " + node . nodeName ) ; console . log ( "元素节点，第一个子节点值为：" + node . firstChild . nodeValue ) ; } else if ( node . nodeType == 3 ) { console . log ( "文本节点：" + node . nodeValue ) ; } console . log ( "\n" ) ; } } }