我想限制 xsd:complexType 只包含 0.5 到 20 之间的值,两者都包括在内,步进 0.5。这意味着数字:
0.5 1 1.5 2 2.5 3 3.5 .. up to 20
我的代码在这里:
<xsd:complexType name="skillType">
<xsd:simpleContent>
<xsd:extension base="skillHalfDoubleType">
<xsd:attribute name="special">
<!-- Irrelevant attribute -->
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="skillHalfDoubleType">
<xsd:restriction base="xsd:double">
<!-- What more? -->
</xsd:restriction>
</xsd:simpleType>
可以通过在 xsd:string 上应用正则表达式来实现,但是我正在寻找限制 xsd:double 的解决方案。
最佳答案
一个简单(虽然冗长)的解决方案是使用枚举:
<xs:enumerationvalue="0.5"/>
<xs:enumerationvalue="1"/>
<xs:enumerationvalue="1.5"/>
...
一个更优雅的解决方案是使用结合了 min 和 maxInclusive 的模式:
<xs:minInclusivevalue="0"/>
<xs:maxInclusivevalue="20"/>
<xs:pattern value="([1-9]?[0-9])|([1-9]?[0-9].5)"/>
正如 C. M. Sperberg-McQueen 所指出的,后者允许更轻松的范围适应,但可能会使一些模式感知建议提供者感到困惑。
关于xml - XSD 允许加倍减半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36389556/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我正在处理旧代码的一部分。beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)endRubocop错误如下:Avoidstubbingusing'allow_any_instance_of'我读到了RuboCop::RSpec:AnyInstance我试着像下面那样改变它。由此beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)end对此:let(:sport_
我正在使用DMOZ的listofurltopics,其中包含一些具有包含下划线的主机名的url。例如:608609TheOuterHeaven610InformationandimagegalleryofMcFarlane'sactionfiguresforTrigun,Akira,TenchiMuyoandotherJapaneseSci-Fianimations.611Top/Arts/Animation/Anime/Collectibles/Models_and_Figures/Action_Figures612虽然此url可以在网络浏览器中使用(或者至少在我的浏览器中可以使用:
我读过这个:Let’sstartwithasimpleRubyprogram.We’llwriteamethodthatreturnsacheery,personalizedgreeting.defsay_goodnight(name)result="Goodnight,"+namereturnresultend我的理解是,方法是定义在类中的函数或子程序,可以关联到类(类方法)或对象(实例方法)。那么,如果它不是在类中定义的,怎么可能是方法呢? 最佳答案 当你在Ruby中以这种方式在全局范围内定义一个函数时,它在技术上变成了Obje
我想禁用HTTP参数的自动XML解析。但我发现命令仅适用于Rails2.x,它们都不适用于3.0:config.action_controller.param_parsers.deleteMime::XML(application.rb)ActionController::Base.param_parsers.deleteMime::XMLRails3.0中的等价物是什么? 最佳答案 根据CVE-2013-0156的最新安全公告你可以将它用于Rails3.0。3.1和3.2ActionDispatch::ParamsParser::
我正在遍历数组中的一组标签名称,我想使用构建器打印每个标签名称,而不是求助于“我认为:builder=Nokogiri::XML::Builder.newdo|xml|fortagintagsxml.tag!tag,somevalendend会这样做,但它只是创建名称为“tag”的标签,并将标签变量作为元素的文本值。有人可以帮忙吗?这个看起来应该比较简单,我刚刚在搜索引擎上找不到答案。我可能没有以正确的方式提问。 最佳答案 尝试以下操作。如果我没记错的话,我添加了一个根节点,因为Nokogiri需要一个。builder=Nokogi
这是一些奇怪的例子:#!/usr/bin/rubyrequire'rubygems'require'open-uri'require'nokogiri'print"withoutread:",Nokogiri(open('http://weblog.rubyonrails.org/')).class,"\n"print"withread:",Nokogiri(open('http://weblog.rubyonrails.org/').read).class,"\n"运行此返回:withoutread:Nokogiri::XML::Documentwithread:Nokogiri::
我正在尝试加载SAML协议(protocol)架构(具体来说:https://www.oasis-open.org/committees/download.php/3407/oasis-sstc-saml-schema-protocol-1.1.xsd),但在执行此操作之后:schema=Nokogiri::XML::Schema(File.read('saml11_schema.xsd'))我得到这个输出:Nokogiri::XML::SyntaxErrorException:Element'{http://www.w3.org/2001/XMLSchema}element',att
在DavidFlanagan的TheRubyProgrammingLanguage中;松本幸弘theystatethatthevariableprefixes($,@,@@)areonepricewepayforbeingabletoomitparenthesesaroundmethodinvocations.谁可以给我解释一下这个? 最佳答案 这是我不成熟的意见。如果我错了,请纠正我。假设实例变量没有@前缀,那么我们如何声明一个实例变量?classMyClassdefinitialize#Herefooisaninstanceva
我已经设法制作了一个仅用于注册和登录的应用程序。目前,我允许用户通过邮件帐户激活(按照本教程:https://www.railstutorial.org/book/account_activation_password_reset和“railsgeneratecontrollerAccountActivations--no-test-framework')但我希望管理员能够激活或停用用户。在我的用户模型中,我设法定义了两种方法:defactivate_account!update_attribute:is_active,trueenddefdeactivate_account!upda