


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

AI Hentai Generator
Generate AI Hentai for free.

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

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

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.

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.

Do you know how to use excel data verification? Below, the editor will bring you how to use excel data verification. I hope it will be helpful to everyone. Let’s learn with the editor! 1. First, in the EXCEL table, select the required Set the cell for the drop-down option, as shown in the figure below: 2. Then click [Data] on the menu bar, as shown in the figure below: 3. After opening the data menu, you will see the [Data Validation] option, click [Data] After verification], continue to click [Data Verification] in the open options to open the data verification window for settings, as shown in the figure below: The above is the entire content of how to use excel data verification brought by the editor. I hope it will be helpful to you. Everyone can help.

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.

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

Introduction XML (Extensible Markup Language) is a popular format for storing and transmitting data. Parsing XML in Java is a necessary task for many applications, from data exchange to document processing. To parse XML efficiently, developers can use various Java libraries. This article will compare some of the most popular XML parsing libraries, focusing on their features, functionality, and performance to help developers make an informed choice. DOM (Document Object Model) parsing library JavaXMLDOMAPI: a standard DOM implementation provided by Oracle. It provides an object model that allows developers to access and manipulate XML documents. DocumentBuilderFactoryfactory=D
