


Detailed explanation of code examples using regular expressions for xml data validation
xml Schema is a data definition file that defines XML, with .xsd as the file extension. It can also be used to define a class of XML files.
Usually, some data with special meaning cannot be clearly described by the system's preset data structure (type).
The XML Schema specification states that simple types can be restricted through facets, thereby generating some new atomic types (Atomic types).
Facet has pattern, enumeration, etc.;
What I want to say here is that one of the very useful ones is:
pattern+ regular expression language (regular exPRession language)
Combined with the power of regular expressions function, you can describe some complex data structures
Examples can be verified through xmlspy, xmlwrite, or js/vbs, etc. The following is an example of js verification (requires msxml4.0 support)
Information about defining XML Schema can be found in Part 1 of the W3C's XML Schema specification. For information about built-in data types and the limitations of their availability, check Part 2 of the XML Schema specification. For a brief summary of these two parts of the XML Schema specification, see W3C Primer on XML Schema.
For regular expressions, you can go to http://www.regexlib.com/ to see
examples:
/*** examples.xml ***/ <?xml version="1.0" encoding="gb2312"?> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="examples.xsd"> <user> <name>test</name> <email>moonpiazza@hotmail.com</email> <ip>127.0.0.1</ip> <color>#000000</color> </user> <user> <name>guest</name> <email>guest@371.net</email> <ip>202.102.224.25</ip> <color>#FFFFFF</color> </user> </root> /*** examples.xsd ***/ <?xml version="1.0" encoding="gb2312"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="root" type="Root"/> <xsd:complexType name="Root"> <xsd:sequence> <xsd:element name="user" type="User" minOccurs="0" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="User"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="email" type="Email" /> <xsd:element name="ip" type="IP" /> <xsd:element name="color" type="Color" /> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="Email"> <xsd:restriction base="xsd:string"> <xsd:pattern value="([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="IP"> <xsd:restriction base="xsd:string"> <xsd:pattern value="(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\. (25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\. (25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="Color"> <xsd:restriction base="xsd:string"> <xsd:pattern value="#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> /*** examples.htm ***/ <SCRIPT LANGUAGE="javaScript"> 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) { //参看书籍教程中parseError对象属性 sReturnVal = sReturnVal + "代码:" + oXML.parseError.errorCode + "\n" ; sReturnVal = sReturnVal + "错误原因:" + oXML.parseError.Reason + "\n" ; sReturnVal = sReturnVal + "错误字符串:" + oXML.parseError.srcText + "\n" ; sReturnVal = sReturnVal + "错误行号" + oXML.parseError.line + "\n" ; sReturnVal = sReturnVal + "错误列数:" + oXML.parseError.linepos + "\n" ; } else { sReturnVal = sReturnVal + "验证通过!" } alert(sReturnVal); } function window.onload() { validate(); } </SCRIPT>
The above is the use of regular expressions Detailed explanation of the code example for expression xml data verification. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP regular expression verification: Number format detection When writing PHP programs, it is often necessary to verify the data entered by the user. One of the common verifications is to check whether the data conforms to the specified number format. In PHP, you can use regular expressions to achieve this kind of validation. This article will introduce how to use PHP regular expressions to verify number formats and provide specific code examples. First, let’s look at common number format validation requirements: Integers: only contain numbers 0-9, can start with a plus or minus sign, and do not contain decimal points. floating point

To validate email addresses in Golang using regular expressions, follow these steps: Use regexp.MustCompile to create a regular expression pattern that matches valid email address formats. Use the MatchString function to check whether a string matches a pattern. This pattern covers most valid email address formats, including: Local usernames can contain letters, numbers, and special characters: !.#$%&'*+/=?^_{|}~-`Domain names must contain at least One letter, followed by letters, numbers, or hyphens. The top-level domain (TLD) cannot be longer than 63 characters.

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

PHP Regular Expressions: Exact Matching and Exclusion Fuzzy inclusion regular expressions are a powerful text matching tool that can help programmers perform efficient search, replacement and filtering when processing text. In PHP, regular expressions are also widely used in string processing and data matching. This article will focus on how to perform exact matching and exclude fuzzy inclusion operations in PHP, and will illustrate it with specific code examples. Exact match Exact match means matching only strings that meet the exact condition, not any variations or extra words.

The method of using regular expressions to verify passwords in Go is as follows: Define a regular expression pattern that meets the minimum password requirements: at least 8 characters, including lowercase letters, uppercase letters, numbers, and special characters. Compile regular expression patterns using the MustCompile function from the regexp package. Use the MatchString method to test whether the input string matches a regular expression pattern.

PHP is a widely used programming language, especially popular in the field of web development. In the process of web development, we often encounter the need to filter and verify text input by users, among which character filtering is a very important operation. This article will introduce how to use regular expressions in PHP to implement Chinese character filtering, and give specific code examples. First of all, we need to clarify that the Unicode range of Chinese characters is from u4e00 to u9fa5, that is, all Chinese characters are in this range.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
