本来是更具体的,如果你发布了输入XML。
假设你不同的样本输入XML我张贴的答案:
样品输入XML:
<?xml version="1.0" encoding="utf-8"?>
<testing>68</testing>
XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="testing" type="citycode" />
<xs:simpleType name="citycode">
<xs:restriction base="xs:int">
<xs:pattern value="68"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
样品输入XML:
<?xml version="1.0" encoding="utf-8"?>
<testing>Blah blah City code is: 68</testing>
XSD [使用r egex图案]:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="testing" type="pattern" />
<xs:simpleType name="pattern">
<xs:restriction base="xs:string">
<xs:pattern value=".*68"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
其中.*
是任意字符(除了换行),68 - 数68
一个多个样品输入XML:
<?xml version="1.0" encoding="utf-8"?>
<testing>Blah blah City code is: '68' and something else</testing>
XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="testing" type="pattern" />
<xs:simpleType name="pattern">
<xs:restriction base="xs:string">
<xs:pattern value=".*68.*"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
发布您的示例输入XML。 – 2013-02-26 12:29:11