【问题标题】:Assert condition to optimize the query in XSD断言条件以优化 XSD 中的查询
【发布时间】:2018-08-07 13:48:29
【问题描述】:

我有一个 XSD,我必须在其中使用断言条件。当指标='A'时,我想打印所有列的条件,而另一个条件是指标='D'的几列。我有以下逻辑,但我有大约 100 列,所以有人可以帮我优化查询吗?

<xs:assert test="if (indicator eq 'A') 
        then test1 and test2 and test3 and test4 and test5 and test6 and test7
        else if (indicator eq 'B') then test1 and test3 
        else false()"/>

输入的 XML 格式如下:

`<?xml version="1.0" encoding="utf-8"?>
<p:CustomerElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <recordCount>1234</recordCount>
  <Customer>
      <indicator>A</indicator>
      <test1>hdjfs</test1>
      <test2>idsfh</test2>
	  <test3>idsfh</test3>
	  <test4>idsfh</test4>
	  <test5>idsfh</test5>
	  <test6>idsfh</test6>
	  <test7>idsfh</test7>
	</Customer>
    <Customer>
      <indicator>B</indicator>
      <test1>abcd</test1>
      <test2></test2>
	  <test3>uydshjk</test3>
	  <test4></test4>
	  <test5></test5>
	  <test6></test6>
	  <test7></test7>
    </Customer>
</p:CustomerElement>

正如我提到的,当 A 填充所有列时,当 B 只有 2 列时。如果我写错了条件,请帮助我使用哪个条件。

指标的值肯定是 A 或 B。

谢谢。

【问题讨论】:

  • @kjhughes 嗨,希望你做得很好!你能帮我解决这个问题吗!谢谢
  • 见下文。如果对你有用请采纳。谢谢。

标签: xml xsd xml-parsing xsd-validation xsd-1.1


【解决方案1】:

为了简化

<xs:assert test="if (indicator eq 'A') 
              then test1 and test2 and test3 and test4 and test5 and test6 and test7
              else if (indicator eq 'B') then test1 and test3 
              else false()"/>

鉴于此声明,

指标的值肯定是 A 或 B。

允许else 覆盖B 案例:

<xs:assert test="if (indicator eq 'A') 
              then test1 and test2 and test3 and test4 and test5 and test6 and test7
              else test1 and test3"/>

接下来,鉴于此陈述[强调添加],

当 A 然后 所有 列填充,当 B 只有 2 列时

为了避免枚举test1test7所有(特别是考虑到你提到的,

我有大约 100 列

只需在断言中限制test1test7 的总数,

<xs:assert test="if (indicator eq 'A') 
                 then (count(*) = 8)
                 else test1 and test3"/>

如果您已经在 parent 的内容模型中明确声明了它们的存在,这将不亚于枚举它们。

作为最后一步,您可以将if else 重写为逻辑等价,

<xs:assert test="   (indicator eq 'A' and count(*) = 8)
                 or (test1 and test3)"/>

但相对于其前身更喜欢这种形式主要是品味问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多