Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用多个XSD'验证XML;红宝石_Xml_Ruby_Xsd_Nokogiri - Fatal编程技术网

使用多个XSD'验证XML;红宝石

使用多个XSD'验证XML;红宝石,xml,ruby,xsd,nokogiri,Xml,Ruby,Xsd,Nokogiri,我正在生成许多XMPP节,并希望根据单元测试中可用的规范对它们进行验证 目前我正在使用Nokogiri来实现这一点,比如 xml = Nokogiri::XML( xmpp_stanza) schema = Nokogiri::XML::Schema( xmpp_schema ) assert schema.valid?( xml ) 现在,它可以正常工作,但会被报告为无效,因为每个模式只包含一个名称空间,并且我的XMPP节有多个名称空间。例如: Invalid XML: Elemen

我正在生成许多XMPP节,并希望根据单元测试中可用的规范对它们进行验证

目前我正在使用Nokogiri来实现这一点,比如

xml    = Nokogiri::XML( xmpp_stanza)
schema = Nokogiri::XML::Schema( xmpp_schema )

assert schema.valid?( xml )
现在,它可以正常工作,但会被报告为无效,因为每个模式只包含一个名称空间,并且我的XMPP节有多个名称空间。例如:

Invalid XML: Element '{http://jabber.org/protocol/pubsub}pubsub': No matching global element declaration available, but demanded by the strict wildcard.

如何处理多个模式来验证单个节?我是不是打算先按名称空间将其分开,并单独验证每个模式?

我能够通过将一个模式转换为另一个模式来实现这一点

e、 g


如果没有其他可用的名称空间,也可以修改模式,在模式中的相关“any”节点上包含processContents=“lax”指令,表示可以不验证没有模式的名称空间。我确实喜欢这样:

schema_xml        = Nokogiri::XML(File.read(path))
schema_xml.xpath("//xs:any[@namespace='##other']", 
  {"xs" => "http://www.w3.org/2001/XMLSchema"}).each do |node|
     node["processContents"] = "lax"
end   
schema = Nokogiri::XML::Schema.from_document( schema_xml )
当然,这意味着不会验证外部名称空间

schema_xml        = Nokogiri::XML(File.read(path))
schema_xml.xpath("//xs:any[@namespace='##other']", 
  {"xs" => "http://www.w3.org/2001/XMLSchema"}).each do |node|
     node["processContents"] = "lax"
end   
schema = Nokogiri::XML::Schema.from_document( schema_xml )