🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: cn.bbs.comp.xml
1 messages
1 total messages Started by WE Fri, 04 Feb 2011 06:07
XML Schema/XQuery & XPath�е�������ʽ
#137
Author: WE
Date: Fri, 04 Feb 2011 06:07
101 lines
6404 bytes
http://www.regular-expressions.info/xml.html
ժҪһ�£�

��Schema����ij����У�������ʽ��Ҫ��������֤Validate��һ�㲻�ᱻ����ƥ��match�ġ�
��֧�ֵĹ��ܣ�
1��û��^$��Ĭ�ϴ��ϣ�
2��û�дʷֽ�� word boundaries
3��û��lookaround
4��.ȱʡƥ�䵥�У���ƥ����п���[\s\S]*regex[\s\S]*
5��û��ָ��ƥ��ģʽ�����絥�ж��У����Դ�Сд��
6��������\xFF��\uFFFF��ʽ���ַ����� ��ʽ
7��û��̰��greedy����lazyģʽ��.+?��.+��)

֧�ֵĹ��ܣ�
1��Character classes, including shorthands, ranges and negated classes.
2��Character class subtraction.
3��The dot, which matches any character except line breaks.
4��Alternation and groups.
5��Greedy quantifiers ?, *, + and {n,m}
6��Unicode properties and blocks

���ԣ�
1�������XML Character classes��\i [_:A-Za-z]. \c [-._:A-Za-z0-9] \I���� \C����
   \i��XMLԪ��������ĸ��\c��Ԫ����������ĸ��\i\c*�ǺϷ���XML element name��
2��֧�ּ����������[a-z-[aeiou]]�Ǹ���[\p{L}-[\p{IsBasicLatin}]]Ӣ����ĸ֮���������ĸ

XQuery & XPath�е�������ʽ��Schema�еĹ���ǿ��
��http://www.regular-expressions.info/xpath.html

======================================================
XML Schema Regular Expressions

The W3C XML Schema standard defines its own regular expression flavor. You can use it in the 
pattern facet of simple type definitions in your XML schemas. E.g. the following defines the 
simple type "SSN" using a regular expression to require the element to contain a valid US 
social security number.

<xsd:simpleType name="SSN">
    <xsd:restriction base="xsd:token">
        <xsd:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{4}"/>
    </xsd:restriction>
</xsd:simpleType>
Compared with other regular expression flavors, the XML schema flavor is quite limited in 
features. Since it's only used to validate whether an entire element matches a pattern or 
not, rather than for extracting matches from large blocks of data, you won't really miss the 
features often found in other flavors. The limitations allow schema validators to be 
implemented with efficient text-directed engines.


Particularly noteworthy is the complete absence of anchors like the caret and dollar, word 
boundaries and lookaround. XML schema always implicitly anchors the entire regular 
expression. The regex must match the whole element for the element to be considered valid. If 
you have the pattern regexp, the XML schema validator will apply it in the same way as say 
Perl, Java or .NET would do with the pattern ^regexp$. If you want to accept all elements 
with regex somewhere in the middle of their contents, you'll need to use the regular 
expression .*regex.*. The to .* expand the match to cover the whole element, assuming it 
doesn't contain line breaks. If you want to allow line breaks, you can use something like 
[\s\S]*regex[\s\S]*. Combining a shorthand character class with its negated version results 
in a character class that matches anything.

XML schemas do not provide a way to specify matching modes. The dot never matches line 
breaks, and patterns are always applied case sensitively. If you want to apply literal case 
insensitively, you'll need to rewrite it as [lL][iI][tT][eE][rR][aA][lL].

XML regular expressions don't have any tokens like \xFF or \uFFFF to match particular (non-
printable) characters. You can use the &#xFFFF; XML syntax for this, or simply copy the 
character directly from a character map.

Lazy quantifiers are not available. Since the pattern is anchored at the start and the end of 
the subject string anyway, and only a success/failure result is returned, the only potential 
difference between a greedy and lazy quantifier would be performance. You can never make a 
fully anchored pattern match or fail by changing a greedy quantifier into a lazy one or vice 
versa.

XML Schema regular expressions support the following:

Character classes, including shorthands, ranges and negated classes.
Character class subtraction.
The dot, which matches any character except line breaks.
Alternation and groups.
Greedy quantifiers ?, *, + and {n,m}
Unicode properties and blocks
Note that the regular expression functions available in XQuery and XPath use a different 
regular expression flavor. This flavor is a superset of the XML Schema flavor described here. 
It adds some of the features that are available in many modern regex flavors, but not in the 
XML Schema flavor.

XML Character Classes

Despite its limitations, XML schema regular expressions introduce two handy features. The 
special short-hand character classes \i and \c make it easy to match XML names. No other 
regex flavor supports these.

Character class subtraction makes it easy to match a character that is in a certain list, but 
not in another list. E.g. [a-z-[aeiou]] matches an English consonant. This feature is now 
also available in the JGsoft and .NET regex engines. It is particularly handy when working 
with Unicode properties. E.g. [\p{L}-[\p{IsBasicLatin}]] matches any letter that is not an 
English letter.
--

�� ��Դ:��ˮľ���� http://newsmth.net��[FROM: 198.80.129.*]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads