断言条件以优化 XSD 中的查询 [英] Assert condition to optimize the query in XSD

查看:19
本文介绍了断言条件以优化 XSD 中的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<xs:assert test="if (indicator eq 'A')然后 test1 和 test2 和 test3 和 test4 和 test5 和 test6 和 test7else if (indicator eq 'B') then test1 and test3else false()"/>

输入的 XML 格式如下:

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

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

指标的值只能确定为 A 或 B.

谢谢.

解决方案

简化

<xs:assert test="if (indicator eq 'A')然后 test1 和 test2 和 test3 和 test4 和 test5 和 test6 和 test7else if (indicator eq 'B') then test1 and test3否则为假()"/>

鉴于此声明,

<块引用>

指标的值只能确定为 A 或 B.

允许 else 覆盖 B 案例:

<xs:assert test="if (indicator eq 'A')然后 test1 和 test2 和 test3 和 test4 和 test5 和 test6 和 test7否则 test1 和 test3"/>

接下来,鉴于此声明[强调],

<块引用>

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

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

我有大约 100 列

只限制断言中test1test7的总数,

<xs:assert test="if (indicator eq 'A')然后(计数(*)= 8)否则 test1 和 test3"/>

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

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

<xs:assert test="(指标 eq 'A' and count(*) = 8)或 (test1 和 test3)"/>

但对这种形式的偏好与其前身相比主要是品味问题.

I have an XSD where i have to use assert condition. I would want to print all columns for condition when indicator='A' and few columns another condition is indicator='D'. I have the below logic but i have around 100 columns so can anyone help me with optimizing the query?

<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()"/>

The input XML is in this format:

`<?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>

So as i mentioned when A then all columns populate and when B only 2 columns. If in case i have written the condition wrong, please help me on using which condition to use.

The values for indicator is A or B only for sure.

Thanks.

解决方案

To simplify

<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()"/>

given this statement,

The values for indicator is A or B only for sure.

allow the else to cover the B case:

<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"/>

Next, given this statement [emphasis added],

when A then all columns populate and when B only 2 columns

to avoid having to enumerate all of test1 through test7 (especially given that you mentioned,

i have around 100 columns

just constrain the total count of test1 through test7 in the assertion,

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

This will be no less strict than enumerating them if you've already declared their existence explicitly in the content model of parent.

As one last step, you might re-write if else to the logically equivalent,

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

but preference for this form over its predecessor is mostly a matter of taste.

这篇关于断言条件以优化 XSD 中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆