我是 xml 语言的新手,我有一个 xml 文件并为该文件创建了 xsd 架构,但我的问题是如何在 xml 文件中引用该架构。我的 xml 架构看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wmh="http://www.wmhelp.com/2003/eGenerator"
elementFormDefault="qualified"
targetNamespace="http://axis.com/service"
xmlns="http://axis.com/service"
version="1.0">
<xs:element name="SWService" type="SWServiceType"/>
<xs:element name="HWService" type="HWServiceType"/>
<xs:complexType name="SWServiceType">
<xs:sequence>
<xs:element name="Service" type="ServiceType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceType">
<xs:complexContent>
<xs:extension base="IdType">
<xs:sequence>
<xs:element name="Description" type="xs:string" maxOccurs="1" minOccurs="0"/>
<xs:element name="ServiceCustomers" type="ServiceCustomersType" maxOccurs="1"
minOccurs="0"/>
<xs:element name="ServiceSuppliers" type="ServiceSuppliersType" maxOccurs="1"
minOccurs="0"/>
</xs:sequence>
<xs:attribute name="Name" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="HWServiceType">
<xs:sequence>
<xs:element name="element" type="elementGroupType" maxOccurs="1" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceCustomersType">
<xs:sequence>
<xs:element name="SoftWare" type="SoftWareType" maxOccurs="unbounded"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceSuppliersType">
<xs:sequence>
<xs:element name="SoftWare" type="SoftWareType" maxOccurs="unbounded"
minOccurs="0"/>
<xs:element name="HardWare" type="HardWareType" maxOccurs="unbounded"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="SoftWareType">
<xs:complexContent>
<xs:extension base="PathType">
<xs:attribute name="Service" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="HardWareType">
<xs:complexContent>
<xs:extension base="PathType">
<xs:attribute name="Type" type="xs:string" use="required"/>
<xs:attribute name="Nr" type="xs:string" use="required"/>
<xs:attribute name="Service" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="PathType">
<xs:attribute name="Path" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="elementGroupType">
<xs:sequence>
<xs:element name="element" type="elementType" maxOccurs="unbounded"
minOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="elementType">
<xs:sequence>
<xs:element name="LM" type="LMType2" maxOccurs="1" minOccurs="1"/>
<xs:element name="Service" type="ServiceType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="Type" type="xs:string" use="required"/>
<xs:attribute name="Nr" type="xs:string" use="required"/>
<xs:attribute name="Name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="LMType2">
<xs:sequence>
<xs:element name="LowerMode" type="LowerModeType2" maxOccurs="unbounded"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="LowerModeType2">
<xs:complexContent>
<xs:extension base="IdType">
<xs:attribute name="Probability" type="xs:double" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="IdType">
<xs:attribute name="Id" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
我将此文件另存为 service.xsd。 我需要在我的 xml 文件中引用这个模式,我试过这样但它没有验证。
<?xml version="1.0" encoding="UTF-8"?>
<Service xsi:schemaLocation="file:///C:/main/newfolder/service.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service"
Version="1.0">
--------Xml data-------
</Service>
我不明白这是什么问题。它给出了这样的错误
No DTD of the document found
我试过这样
<?xml version="1.0" encoding="UTF-8"?>
<Service xsi:schemaLocation=""http://axis.com/service"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service"
Version="1.0">
--------Xml data-------
</Service>
还是一样的问题。 当我使用 xmlpad 验证 xml 文件时。 任何人都可以解决我的问题。感谢任何帮助
提前致谢。
最佳答案
schemaLocation 的使用完全是可选的,并且 Version 属性在您的实例中不正确(除非您在您的模式中定义了一个名为 Version 的属性)
下面的例子
<Service xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service">
any string
</Service>
根据模式验证良好:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wmh="http://www.wmhelp.com/2003/eGenerator"
elementFormDefault="qualified"
targetNamespace="http://axis.com/service"
xmlns="http://axis.com/service"
version="1.0">
<xs:element name="Service" type="xs:string"/>
</xs:schema>
我所做的只是将您的类型 AxisServiceType 替换为字符串。
为了确定您遇到的失败的确切原因,我需要查看您的整个架构和实例文档。
关于xml - 在 xml 中引用 xsd 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8488122/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A