我在一台服务器上验证空值时遇到一些问题,但它适用于我的所有其他服务器。该问题出现在较新的 PHP 版本 (5.3.8) 上,但适用于稍旧的版本 (5.2.4)。
这里有几个孤立的失败元素:
XML 输入:
<clbburnfuelbias></clbburnfuelbias>
<clbburntimebias></clbburntimebias>
XSD 验证:
<xs:element name="clbburnfuelbias" type="data-fuelbias"/>
<xs:element name="clbburntimebias" type="data-timebias"/>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="data-timebias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-59"/>
<xs:maxInclusive value="59"/>
</xs:restriction>
</xs:simpleType>
错误:
Error 1824: Element 'clbburnfuelbias': The value is not a valid value of the atomic type 'data-fuelbias'. Error 1824: Element 'clbburntimebias': The value is not a valid value of the atomic type
'data-timebias'.
在运行 5.2.4 的不同服务器上使用完全相同的输入和 XSD 文件,我没有收到任何错误并且 xml 有效。
我已经尝试将 minOccurs="0"添加到元素中,我也尝试指定 nullable="true"但仍然出现错误。
似乎空值在我使用 PHP 5.2.4 的服务器上被忽略,并在使用 5.3.8 时被拒绝。我使用过的解决方法是使用两个定义的联合,一个用于整数类型,一个用于空值:
XSD:
<xs:element name="clbburnfuelbias" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="data-fuelbias null-string"/>
</xs:simpleType>
</xs:element>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="null-string">
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
最佳答案
将元素设为可选 (minOccurs="0") 不会使其内容成为通配符。如果元素出现,它必须与声明的类型匹配。
如果元素具有 xsi:nil="true" 属性,则使元素可为空 (nillable="true") 允许元素为空,其中 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance":
<clbburnfuelbias xsi:nil="true"></clbburnfuelbias>
<clbburntimebias xsi:nil="true"></clbburntimebias>
您也可以使用联合类型,它仅具有相同的含义用于验证目的:
<xs:simpleType name="data-fuelbias">
<xs:union>
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:union>
</xs:simpleType>
关于php - 为什么我的 xml 无法通过 XSD 验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13237493/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为