我定义了两种复杂的元素类型 - Developer 和 App。
开发者 child - ID、姓名、电子邮件
应用子项 - ID、名称、开发人员
这里App复杂元素中的Developer是指Developer/ID。
如何在 xml 模式中定义这种关系。我正在使用 XML spy2013 编辑器。
我尝试在简单类型 Developer->ID 的声明中指定名称。并在 App->Developer 数据类型中使用此名称。但它给出了错误..
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2013 (x64) (http://www.altova.com) by Piyush (USC) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="appinfo">
<xs:complexType>
<xs:sequence>
<xs:element name="Developer">
<xs:complexType>
<xs:all>
**<xs:element name="ID">**
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="5"/>
<xs:pattern value="[a-zA-Z][a-zA-Z][0-9][0-9][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z])+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Email">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[^@]+@[^\.]+\..+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Company" type="xs:string"/>
<xs:element name="Website" type="xs:string"/>
<xs:element name="Phone">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="13"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="App">
<xs:complexType>
<xs:all>
<xs:element name="ID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="5"/>
<xs:pattern value="[0-9][0-9][0-9][0-9][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z])+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Developer" ***type="xs:anySimpleType"/>***
<xs:element name="Price">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:minInclusive value="0.00"/>
<xs:maxInclusive value="6.99"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="TabletCompatible" type="xs:boolean" minOccurs="0"/>
<xs:element name="Category">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Travel"/>
<xs:enumeration value="Productivity"/>
<xs:enumeration value="Game"/>
<xs:enumeration value="Music"/>
<xs:enumeration value="Education"/>
<xs:enumeration value="Lifestyle"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Platform">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Android"/>
<xs:enumeration value="iOS"/>
<xs:enumeration value="Blackberry"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="AppStat">
<xs:complexType>
<xs:all>
<xs:element name="AppID" type="xs:anySimpleType"/>
<xs:element name="Statistics">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Platform" type="xs:anySimpleType"/>
<xs:element name="Downloads" type="xs:positiveInteger"/>
<xs:element name="Rating">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:minInclusive value="0.0"/>
<xs:maxInclusive value="5.0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LastChecked" type="xs:date"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
最佳答案
开发者id使用普通简单类型的方法是在开头声明为命名类型:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:simpleType name="developerID">
<xs:restriction base="xs:string">
<xs:length value="5"/>
<xs:pattern value="[a-zA-Z][a-zA-Z][0-9][0-9][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
. . .
然后使用它:
. . .
<xs:element name="Developer" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="ID" type="developerID">
. . .
<xs:element name="App" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
. . .
<xs:element name="Developer" type="developerID"/>
但这不足以创建一个约束,使 appinfo/App/Developer 只能包含在 appinfo/Developer/ID 中声明的开发人员 ID 之一。为此,有必要使用 xs:key 创建一个唯一的键定义,并使用 xs:keyref 引用它(参见 here )。
这是完整的 XSD:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:simpleType name="developerID">
<xs:restriction base="xs:string">
<xs:length value="5"/>
<xs:pattern value="[a-zA-Z][a-zA-Z][0-9][0-9][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="appinfo">
<xs:complexType>
<xs:sequence>
<xs:element name="Developer" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="ID" type="developerID">
</xs:element>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z])+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Email">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[^@]+@[^\.]+\..+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Company" type="xs:string"/>
<xs:element name="Website" type="xs:string"/>
<xs:element name="Phone">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="13"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="App" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="ID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="5"/>
<xs:pattern value="[0-9][0-9][0-9][0-9][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z])+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Developer" type="developerID"/>
<xs:element name="Price">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:minInclusive value="0.00"/>
<xs:maxInclusive value="6.99"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="TabletCompatible" type="xs:boolean" minOccurs="0"/>
<xs:element name="Category">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Travel"/>
<xs:enumeration value="Productivity"/>
<xs:enumeration value="Game"/>
<xs:enumeration value="Music"/>
<xs:enumeration value="Education"/>
<xs:enumeration value="Lifestyle"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Platform">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Android"/>
<xs:enumeration value="iOS"/>
<xs:enumeration value="Blackberry"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
<xs:keyref name="developerIDref" refer="developerID">
<xs:selector xpath="."/>
<xs:field xpath="Developer"/>
</xs:keyref>
</xs:element>
<xs:element name="AppStat">
<xs:complexType>
<xs:all>
<xs:element name="AppID" type="xs:anySimpleType"/>
<xs:element name="Statistics">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Platform" type="xs:anySimpleType"/>
<xs:element name="Downloads" type="xs:positiveInteger"/>
<xs:element name="Rating">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:minInclusive value="0.0"/>
<xs:maxInclusive value="5.0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LastChecked" type="xs:date"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="developerID">
<xs:selector xpath="Developer"/>
<xs:field xpath="ID"/>
</xs:key>
</xs:element>
</xs:schema>
关于xml - 如何在 XML 模式中定义用户定义数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410842/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我正在使用的第三方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
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende