这应该工作吗?
当我使用
<xs:pattern value="(!red|green|blue)"/>
一切都很好,但使用:
<xs:pattern value="(?!red|green|blue)"/>
(注意添加的“?”)
编辑:在另一个 SO 问题中发现了这个,它也不起作用:
^((?!red|green|blue)|((red|green|blue).+)).*$
两个原因:
/home/asdf/.rvm/gems/ruby-1.9.3-p125@tretti_order/gems/nokogiri-1.5.2/lib/nokogiri/xml/schema.rb:37:in `from_document': Element '{http://www.w3.org/2001/XMLSchema}pattern': The value '(?!red|green|blue' of the facet 'pattern' is not a valid regular expression. (Nokogiri::XML::SyntaxError)
from /home/asdf/.rvm/gems/ruby-1.9.3-p125@tretti_order/gems/nokogiri-1.5.2/lib/nokogiri/xml/schema.rb:37:in `new'
from /home/asdf/.rvm/gems/ruby-1.9.3-p125@tretti_order/gems/nokogiri-1.5.2/lib/nokogiri/xml/schema.rb:8:in `Schema'
from xml_validate.rb:12:in `<main>'
语境:
<xs:simpleType name="attributeIdType">
<xs:annotation>
<xs:appinfo>Attribute Id Type.</xs:appinfo>
<xs:documentation source="http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/Part01/fieldsDef.html#SFDouble"/>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:pattern value="(?!red|green|blue)"/>
</xs:restriction>
</xs:simpleType>