【发布时间】:2014-02-25 15:30:59
【问题描述】:
我真的是 XSD 的“菜鸟”,但我正在尽力而为。
我有这个 XML:
<nombre_completo xmlns:xsi="xxxx "xsi:noNamespaceSchemaLocation="nombre_completo.xsd">
<nombre>Jame Ruiz</nombre>
<apellido1>Sancho</apellido1>
<apellido2>Vera</apellido2>
</nombre_completo>
还有这个 XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="nombre_completo">
<xs:complexType>
<xs:sequence>
<xs:element name="nombre" type="verificar_nombre"/>
<xs:element name="apellido1" type="xs:string"/>
<xs:element name="apellido2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="verificar_nombre">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z]*"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
我希望它验证名称部分。以示例组合名称:Miguel Angel、Jaime Ruiz。或者只是一个名字,比如“Ramon”或“John”。
我试过了:
[a-zA-Z]* [a-zA-Z]?
但什么都没有。
【问题讨论】:
-
你使用
[a-zA-Z]会拒绝我的名字,我兄弟的名字,以及像 Gabriel García Márquez 这样的名字。 -
您能解释一下为什么要拒绝“Gabriel García Márquez”或“Gus O'Donnell”等有效名称吗?
标签: xml regex xsd xsd-validation