Use regular expressions to perform XML data verification
XML Schema is a definition of xml data definition file ? XSD as an extension of the file. It is also used to define a class XML file.
Typically, some special meanable data cannot be clearly described through the system preset data structure (type).
Declaring in the XML Schema specification: You can limit the simple type by Facet, resulting in some new atomic types (Atomic Types).
Facet has Pattern, Enumeration, etc .;
What is the useful in this is:
Pattern Regular Expression Language (Regular Expression Language)
Combined with the powerful function of the regular expression, some complex data structures can be made
Examples can be verified by XMLSPY, XMLWRITE, or JS / VBS, etc., the following example (MSXML4.0 support) is mentioned below.
Information on defining XML Schema can be found in the first part of the XML Schema specification of W3C. For information on built-in data types and limitations thereof, check the second part of the XML Schema specification. For a simple summary of these two parts XML Schema specification, please check the W3C Primer on XML Schema.
For regular expressions, you can go to http://www.regexlib.com/
EXAMPLES:
/ *** Examples.xml *** /
XML Version = "1.0" encoding = "GB2312"?>
user>
user>
root>
/ *** examples.xsd *** /
XML Version = "1.0" encoding = "GB2312"?>
xsd: complexType>
xsd: sequence>
xsd: complexType>
xsd: restriction>
xsd: SimpleType>
xsd: restriction>
xsd: SimpleType>
xsd: restriction>
xsd: SimpleType>
xsd: schema>
/ *** examples.htm *** /
Function validate ()
{
Var oxml;
Var NPARSEERROR; VAR SRETURNVAL;
OXML = New ActiveXObject ("msxml2.domdocument.4.0");
OXML.ASYNC = FALSE;
Oxml.validateonParse = true;
OXML.LOAD ("Examples.xml");
NPARSEERROR = OXML.PARSEERROR.ErrorCode;
Sreturnval = ""
IF (0! = nParseerror)
{
// Refer to the ParseError object attribute in the book tutorial
Sreturnval = SRETURNVAL "Code:" Oxml.Parseerror.Errorcode "/ N";
Sreturnval = SRETURNVAL "Error Cause:" Oxml.Parseerror.reason "/ N";
Sreteval = SRETURNVAL "Error String:" Oxml.Parseerror.SrcText "/ N";
Sreturnval = SRETURNVAL "Error Bode" Oxml.Parseerror.Line "/ N";
Sreturnval = SRETURNVAL "Error Columns:" Oxml.Parseerror.LinePOS "/ N";
}
Else
{
Sreteval = SRETURNVAL "Verification"! "
}
Alert (sreturnval);
}
Function window.onload ()
{
Validate ();
}
Script>