<head>
<script type="text/javascript">
function CreateMSXMLDocumentObject () {
if (typeof (ActiveXObject) != "undefined") {
var progIDs = [
"Msxml2.DOMDocument.6.0",
"Msxml2.DOMDocument.5.0",
"Msxml2.DOMDocument.4.0",
"Msxml2.DOMDocument.3.0",
"MSXML2.DOMDocument",
"MSXML.DOMDocument"
];
for (var i = 0; i < progIDs.length; i++) {
try {
return new ActiveXObject(progIDs[i]);
} catch(e) {};
}
}
return null;
}
function BuildXMLFromString (text) {
var message = "";
if (window.DOMParser) { // all browsers, except IE before version 9
var parser = new DOMParser();
try {
xmlDoc = parser.parseFromString (text, "text/xml");
} catch (e) {
// if text is not well-formed,
// it raises an exception in IE from version 9
alert ("XML parsing error.");
return false;
};
}
else { // Internet Explorer before version 9
xmlDoc = CreateMSXMLDocumentObject ();
if (!xmlDoc) {
alert ("Cannot create XMLDocument object");
return false;
}
xmlDoc.loadXML (text);
}
var errorMsg = null;
if (xmlDoc.parseError && xmlDoc.parseError.errorCode != 0) {
errorMsg = "XML Parsing Error: " + xmlDoc.parseError.reason
+ " at line " + xmlDoc.parseError.line
+ " at position " + xmlDoc.parseError.linepos;
}
else {
if (xmlDoc.documentElement) {
if (xmlDoc.documentElement.nodeName == "parsererror") {
errorMsg = xmlDoc.documentElement.childNodes[0].nodeValue;
}
}
else {
errorMsg = "XML Parsing Error!";
}
}
if (errorMsg) {
alert (errorMsg);
return false;
}
alert ("Parsing was successful!");
return true;
}
function TestContent1 () {
var xmlText = "<root><fruit color='red'></root>";
BuildXMLFromString (xmlText);
}
function TestContent2 () {
var xmlText = "<root><fruit color='red'></fruit></root>";
BuildXMLFromString (xmlText);
}
</script>
</head>
<body>
<span><root><fruit color='red'></root></span><br />
<button onclick="TestContent1 ()">Build XML</button>
<br /><br />
<span><root><fruit color='red'></fruit></root></span><br />
<button onclick="TestContent2 ()">Build XML</button>
<div id="info"></div>
</body>
分享到:
相关推荐
Introduction This example shows the use of sessions and illustrates several SessionManagers: TROEventSessionManager, TROInMemorySessionManager, TROMasterServerSessionManager and TRODBSessionManager. ...
The Art of Debugging illustrates the use of three of the most popular debugging tools on Linux/Unix platforms: GDB, DDD, and Eclipse. In addition to offering specific advice for debugging with each ...
Written from the perspective of the designer of an operating system, this book tackles important issues and practical problems on how to understand an operating system completely and systematically....
This paper illustrates the use of modeling and optimization in informing system design by generating different design alternatives that con- tain these trade-offs, thus allowing the design engineers ...
The last chapter in each part illustrates the use of the newly introduced objects and methods in designing a practical application for Excel. Part VI contains three appendixes that provide basic ...
Use Cases, Applications, and Technology Solutions describes insufficiencies and challenges of 4G in the light of impending and crucial future communication needs, details lessons learned from an ...
Each chapter illustrates the theory of cable and wireless communications with relevant examples, hands-on exercises, and review questions suitable for readers with a BSc degree or an MSc degree in ...
in part due to their use in finding algorithms in approximation theory, this timely book revives the approach of Wallis, Brouncker and Euler and illustrates the continuing significance of their ...
The first, which covers the basic mechanisms of goroutines and channels, illustrates the style known as communicating sequential processes for which Go is renowned. The second covers more traditional...
Exploring methods for the processing of signals in the optical domain, the book includes solutions to photonic circuits that use signal flow techniques and significant applications in short pulse ...
this practical guide not only teaches you the fundamental parts of SciPy and libraries related to it, but also gives you a taste for beautiful, easy-to-read code that you can use in practice....
But in truth, the skill needed is that of managing complexity - to save time performing common system administration tasks, to allow safe use of untrained and trained help in maintaining mission-...
Illustrates and compares features of the most popular Common Lisp systems on desktop computers. Includes discussion and examples of advanced constructs for iteration, error handling, object oriented ...
Big Data: Algorithms, Analytics, and Applications bridges the gap between the vastness of Big Data and the appropriate computational methods for scientific and social discovery. It covers fundamental...
This paper illustrates some salient dispersion properties of the Coifman scaling function based MRTD technique (Coifman S-MRTD) and discusses its applicability to modeling problems of interest. Having...
The sample illustrates the use of the different thumbnail handler APIs to register thumbnail extraction Component Object Model (COM) servers for custom file types. This topic walks you through the ...
This document expands on the representation and governance model of the EGI operations community and illustrates the internal processes needed to ensure the interworking of operations services, and ...