本來是更具體的,如果你發佈了輸入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