XML self-defined checker syntax + constraints (1)

Source: Internet
Author: User

Every time you use it to check the XML file, you only need to change the file name in xmldoc. Load ("XML file name"); and then put the file in the browser for execution.

Based on the dialog box that appears in the browser, determine whether the XML you write meets the DTD constraints.

Note:

1. Correct XML file: No syntax error

Valid XML file: The syntax is correct and meets the DTD constraints.

2. You can only use IE to try it out. The try 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">
<! -- Describe a student's information with DTD -->
<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 self-defined checker syntax + constraints (1)

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.