Every time you use it to check the XML file, you only need to modify the file name in xmldoc. Load ("XML file name"); and then put the file in the browser to run.
Determine whether the XML you write meets the DTD Constraints Based on the dialog box that appears in the browser.
Note:
1. Correct XML file: No syntax error
Valid XML file: The syntax is correct and meets the DTD constraints.
2. This can only be tested using IE browser, but the test using Firefox is invalid.
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> Yi ye Binzhou </title>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
// Create an IE built-in parser
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
// Enable XML Verification
Xmldoc. validateonparse = "true ";
// Load the XML file to be checked
Xmldoc. Load ("arg_entity.xml ");
// Correct
If (xmldoc. parseerror. Reason. Length = 0 ){
Window. Alert ("valid XML file (correct syntax + DTD constraint ");
// Error
} Else {
Window. Alert (xmldoc. parseerror. Reason );
}
</SCRIPT>
</Body>
</Html>
Self-written XML file: (class. XML)
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype person system "class. DTD">
<! -- Use DTD to describe the information of a student -->
<Person>
<Student>
<Name> Yi ye Binzhou </Name>
<Age> 23 | </age>
<Sex> male </sex>
</Student>
<Student>
<Name> no regrets </Name>
<Age> 20 </age>
<Sex> male </sex>
</Student>
</Person>
Defined DTD constraint file: (class. DTD)
<? XML version = "1.0" encoding = "UTF-8"?>
<! Element person (student +)>
<! Element student (name, age, sex)>
<! Element name (# pcdata)>
<! Element age (# pcdata)>
<! Element sex (# pcdata)>
Effect:
XML custom checker syntax + constraints (1)