Create a DOM object named javascept

Source: Internet
Author: User

Function loadxml (flag, XML ){

VaR xmldoc;

// For IE browsers

If (window. activexobject ){

VaR aversions = ["msxml2.domdocument. 6.0", "msxml2.domdocument. 5.0", "msxml2.domdocument. 4.0", "msxml2.domdocument. 3.0", "msxml2.domdocument", "Microsoft. xmldom"];

For (VAR I = 0; I <aversions. length; I ++ ){

Try {

// Create an XML Object

Xmldoc = new activexobject (aversions [I]);

Break;

} Catch (oerror ){

}

}

If (xmldoc! = NULL ){

// Load XML data in synchronous Mode

Xmldoc. async = false;

// Load according to the XML document name

If (flag = true ){

Xmldoc. Load (XML );

} Else {

// Load according to the string that represents the XML document

Xmldoc. loadxml (XML );

}

// Return the root element node of the XML document.

Return xmldoc.doc umentelement;

}

} Else {

// For non-ie browsers

If (document. Implementation & document. Implementation. createdocument ){

/*

The first parameter indicates the URL of the namespace used by the XML document.

The second parameter indicates the name of the root node of the XML document to be created.

The third parameter is a doctype object, which indicates the definition of doctype in the XML document to be created. Generally, null is used directly.

Here we need to load an existing XML document, so first create an empty document, so use the following method

*/

Xmldoc = Document. Implementation. createdocument ("", "", null );

If (xmldoc! = NULL ){

// Load according to the XML document name

If (flag = true ){

// Load XML data in synchronous Mode

Xmldoc. async = false;

Xmldoc. Load (XML );

} Else {

// Load according to the string that represents the XML document

VaR oparser = new domparser ();

Xmldoc = oparser. parsefromstring (XML, "text/XML ");

}

// Return the root element node of the XML document.

Return xmldoc.doc umentelement;

}

}

}

Return NULL;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.