Javascript can be used to load XML files, and then process the corresponding XML files based on the obtained xmldoc object. For example, add, delete, modify, and query nodes and attributes. Here we provide a method for loading XML files.
JSCodeAs follows:
Function Getxmldocument (fileurl ){
VaR Xmldoc;
Try { // Internet Explorer
Xmldoc = New Activexobject ("Microsoft. xmldom ");
}
Catch (E ){
Try {/* Firefox, Mozilla, opera, etc. */
Xmldoc = Document. Implementation. createdocument ("","", Null );
}
Catch (E ){
Alert (E. Message );
Return ;
}
}
Xmldoc. async = False ; // Disable asynchronous loading to ensure that the parser does not continue to execute the script until the file is fully loaded.
Xmldoc. Load (fileurl );
Return Xmldoc;
}
The fileurl parameter here is the path of the XML file. If the content of the XML file is passed directly, xmldoc should be used for loading. loadxml ("XML file content"); then you can use selectsinglenode ("... "), selectnodes ("... "); and so on.