草庐IT

xml - 命名空间 "x"中的元素 "xSchema"在命名空间 "y"中具有无效的子元素 "xSchema"。预期的可能元素列表 : "y"

coder 2024-06-23 原文

我正在为我的 XML 验证最终编写一个模式,并最终使一切(几乎)正常工作。但是现在我的 XML 中出现了最奇怪的错误。我将从展示我的架构开始,因为这应该是问题所在,但它没有给我任何错误。

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:os="OrdersSchema"
        targetNamespace="OrdersSchema"
        elementFormDefault="unqualified"
        attributeFormDefault="qualified">
  <element name="orders"    type="os:orders"/>
  <complexType name="orders">
    <sequence>
      <element name="order" type="os:order" maxOccurs="unbounded"/>
    </sequence>
  </complexType>
  <complexType name="order">
    <sequence>
      <element name="deliveryAddress">
        <complexType>
          <sequence>
            <element name='line1' type='os:lineType'/>
            <element name='line2' type='os:lineType'/>
            <element name='line3' type='os:lineType'/>
            <element name='line4' type='os:lineType' minOccurs='0'/>
          </sequence>
          <attribute name="orderId" type="string" use="required" >
          </attribute>
          <attribute name="type" type="os:typeType" use="required"/>
        </complexType>
        <unique name="uniqueOrderIdPerOrder">
          <selector xpath="os:order"/>
          <field xpath="orderId"/>
        </unique>
      </element>
      <element name='items'>
        <complexType>
          <attribute name='productId' type='os:productIdType'/>
          <attribute name='quantity'>
            <simpleType>
              <restriction base='positiveInteger'>
              </restriction>
            </simpleType>
          </attribute>
        </complexType>
      </element>
      <element name='note' minOccurs='0' type='string'/>
    </sequence>
  </complexType>

  <simpleType name='lineType'>
    <restriction base='string'>
      <minLength value='1'/>
    </restriction>
  </simpleType>
  <simpleType name='typeType'>
    <restriction base='string'>
      <enumeration value='standard'/>
      <enumeration value='express'/>
    </restriction>
  </simpleType>
  <simpleType name='productIdType'>
    <restriction base='string'>
      <pattern value='(?i)p[-\s](150|1[0-4][0-9]|[[1-9][0-9]|[1-9])\.[a-z][a-z][a-z][a-z][a-z][a-z]'/>
      <pattern value='A...+[$XYZ]\b'/>
    </restriction>
  </simpleType>



</schema>

现在,我的架构完全没有错误,但是当我将 XML 文件链接到它时,我收到一条错误消息:命名空间“OrdersSchema”中的元素“orders”在命名空间“OrdersSchema”中具有无效的子元素“order” '.预期的可能元素列表:'order'。

如果有人想尝试一下,这里有一个应该验证的代码:

<?xml version="1.0" encoding="utf-8" ?>
<os:orders xmlns:os="OrdersSchema">
  <os:order orderId="ord0001" type="standard">
    <deliveryAddress>
      <line1>5, Elmstreet</line1>
      <line2>90210 Beverly Hills</line2>
      <line3>California</line3>
    </deliveryAddress>
    <items>
      <item productId="P 150.aabaac" quantity="5" />
    </items>
    <note>Deliver after 5 pm.</note>
  </os:order>
  <os:order orderId="ord0003" type="express">
    <deliveryAddress>
      <line1>Voskenslaan 30</line1>
      <line2>BE9000 Gent</line2>
      <line3>Oost-Vlaanderen</line3>
      <line4>Belgium</line4>
    </deliveryAddress>
    <items>
      <item productId="A3546sdfsdf6546sdf654Z" quantity="10" />
      <item productId="p 149.SLKDOZ" quantity="5" />
      <item productId="P 100.xcvZEr" quantity="15" />
    </items>
  </os:order>
  <os:order orderId="ord0002" type="express">
    <deliveryAddress>
      <line1>Voskenslaan 32</line1>
      <line2>BE9000 Gent</line2>
      <line3>Oost-Vlaanderen</line3>
      <line4>Belgium</line4>
    </deliveryAddress>
    <items>
      <item productId="P-99.ruioze" quantity="15" />
      <item productId="A123qze46548X" quantity="50" />
      <item productId="P 1.sqmfze" quantity="1" />
      <item productId="AoknY" quantity="20" />
    </items>
    <note>This is <b>very urgent</b> !</note>
  </os:order>
</os:orders>

最佳答案

您对

的使用
elementFormDefault="unqualified"
attributeFormDefault="qualified"

非常不寻常,可能是问题的根源。除非你真的想做一些不寻常的事情,否则这些应该是相反的。

关于xml - 命名空间 "x"中的元素 "xSchema"在命名空间 "y"中具有无效的子元素 "xSchema"。预期的可能元素列表 : "y",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21009632/

有关xml - 命名空间 "x"中的元素 "xSchema"在命名空间 "y"中具有无效的子元素 "xSchema"。预期的可能元素列表 : "y"的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用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时

  3. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  4. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是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

  5. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从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""-

  6. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    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上找到一个类似的问题

  7. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  8. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  9. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

  10. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

随机推荐