我正在尝试创建一个 XSD 文件作为过滤器来验证一些必须进一步处理的 XML 文件。
这是 XSL 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<acknowledgement xmlns="http://sungardams.com/Validation.xsd" xmlns:common="http://sungardams.com/common.xsd">
<type>POSITIVE</type> <!-- must have value POSITIVE -->
<originReference>
<externalMessageId>12345678-010</externalMessageId>
</originReference>
<requestMessageId>000000000000000000000000001</requestMessageId>
<senderInfo>
<common:messageId>000000000000000000000000000001</common:messageId>
<common:externalMessageType>securityAddRequest</common:externalMessageType> <!-- must have value securityAddRequest -->
<common:applicationHistory>
<common:originatorReference>
<common:originator>GLOBAL PLUS</common:originator> <!-- must have value GLOBAL PLUS -->
<common:reference>ABCDE001</common:reference>
<common:primaryReferenceType>GREF</common:primaryReferenceType> <!-- must have value GREF -->
</common:originatorReference>
</common:applicationHistory>
</senderInfo>
</acknowledgement>
我收到的文件使用另一个 XSD 文件进行验证,并使用命名空间 common(解释为什么某些元素以 common: 为前缀)。
所以我创建了以下 XSD 文件:
验证.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:common="http://sungardams.com/common.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://sungardams.com/common.xsd" schemaLocation="http://sungardams.com/common.xsd antCommon001.xsd"/>
<xs:element name="acknowledgement">
<xs:complexType>
<xs:sequence>
<xs:element name="type" type="xs:string" fixed="POSITIVE" />
<xs:element name="originReference">
<xs:complexType>
<xs:sequence>
<xs:element name="externalMessageId" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="requestMessageId" type="xs:string" />
<xs:element name="senderInfo" type="CType_SenderInfo_ant" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
最初,元素senderInfo 是在这个文件中定义的。但是当我那样尝试时,我会收到错误消息,指出我的元素无效(我会在名称前加上命名空间 common:,所以会收到消息说它们无效有效的 xs:NCName)。
所以我将发件人信息移到了另一个文件中:antCommon001.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CType_SenderInfo_ant">
<xs:complexType>
<xs:sequence>
<xs:element name="messageId" type="xs:string" />
<xs:element name="externalMessageType" type="xs:string" fixed="securityAddRequest" />
<xs:element name="applicationHistory">
<xs:complexType>
<xs:sequence>
<xs:element name="originatorReference">
<xs:complexType>
<xs:sequence>
<xs:element name="originator" type="xs:string" fixed="GLOBAL PLUS" />
<xs:element name="reference" type="xs:string" />
<xs:element name="primaryReferenceType" type="xs:string" fixed="GREF" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
现在,当我运行 XML 文件的验证时,我收到消息(使用 Notepad++ XML 工具验证插件):
Unable to parse schema file ... element decl. 'senderInfo', attribute 'type': The QName value 'CType_SenderInfo_ant' does not resolve to a(n) type definition.
我做错了什么?
最佳答案
您必须进行多项更改,包括:
xs:import/@schemaLocation 不应是 namespace -XSDurl 对,因为
它用于 xs:schema/@schemaLocation——它应该只是指向的 URL
XSD。总而言之,通过一些额外的修复,以下对您的 XML 和 XSD 文件的更新将成功验证您的 XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<acknowledgement xmlns="http://sungardams.com/Validation.xsd"
xmlns:common="http://sungardams.com/common.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://sungardams.com/Validation.xsd Validation.xsd">
<type>POSITIVE</type> <!-- must have value POSITIVE -->
<originReference>
<externalMessageId>12345678-010</externalMessageId>
</originReference>
<requestMessageId>000000000000000000000000001</requestMessageId>
<senderInfo>
<common:messageId>000000000000000000000000000001</common:messageId>
<common:externalMessageType>securityAddRequest</common:externalMessageType> <!-- must have value securityAddRequest -->
<common:applicationHistory>
<common:originatorReference>
<common:originator>GLOBAL PLUS</common:originator> <!-- must have value GLOBAL PLUS -->
<common:reference>ABCDE001</common:reference>
<common:primaryReferenceType>GREF</common:primaryReferenceType> <!-- must have value GREF -->
</common:originatorReference>
</common:applicationHistory>
</senderInfo>
</acknowledgement>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:common="http://sungardams.com/common.xsd"
targetNamespace="http://sungardams.com/Validation.xsd"
elementFormDefault="qualified">
<xs:import namespace="http://sungardams.com/common.xsd"
schemaLocation="antCommon.xsd"/>
<xs:element name="acknowledgement">
<xs:complexType>
<xs:sequence>
<xs:element name="type" type="xs:string" fixed="POSITIVE" />
<xs:element name="originReference">
<xs:complexType>
<xs:sequence>
<xs:element name="externalMessageId" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="requestMessageId" type="xs:string" />
<xs:element name="senderInfo" type="common:CType_SenderInfo_ant" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://sungardams.com/common.xsd"
elementFormDefault="qualified">
<xs:complexType name="CType_SenderInfo_ant">
<xs:sequence>
<xs:element name="messageId" type="xs:string" />
<xs:element name="externalMessageType" type="xs:string"
fixed="securityAddRequest" />
<xs:element name="applicationHistory">
<xs:complexType>
<xs:sequence>
<xs:element name="originatorReference">
<xs:complexType>
<xs:sequence>
<xs:element name="originator" type="xs:string"
fixed="GLOBAL PLUS" />
<xs:element name="reference" type="xs:string" />
<xs:element name="primaryReferenceType"
type="xs:string" fixed="GREF" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
关于xml - 验证中的 "Elements ... does not resolve to a(n) type definition",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41879602/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我试图在一个项目中使用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时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从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""-
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上找到一个类似的问题
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为