xpath - 如何使方法B工作?

时间:2011-12-28 19:28:32

标签: xpath biztalk biztalk-2009

使用方法A的模式和xpath来读取和映射无界节点(“detail”)正在输出多个消息。唯一的问题是设计xsd模式,无界节点必须始终在一个序列中。 在我正在使用的Message Assignment对象中,我尝试读取和映射的实例XPath是

XPathVar = System.String.Format(“
    /* [local-name()=’header’ and namespace-uri()=’http://namespace’]
    /* [local-name()=’detail’ and namespace-uri()=’http://namespace’] and 
    position() = {0}]”, nLoopCount)

如果我在detail节点之后没有header节点,那么它会失败,抛出类似于'的异常,在构造块的末尾包含一个空值”。有没有办法让方法B工作? 即

此方法有效!

    [Method A]
    <schema>
       <header>  (Node)
           <detail> (Node) unbounded
             <child elements> 
           </detail>
           <additional info> (Node)
             <child elements>
           </additional info>
       </header>

但是这不起作用并抛出类似于'在构造块末尾包含空值'的异常

    [Method B]
    <schema>
      <header> (Node)
         <additional info> (Node)
            <child elements>
         </additional info>
         <detail> (Node) unbounded
            <child elements> 
         </detail>
      </header>

如果有其他元素或节点将&lt;标题&gt;和&lt;细节&gt;在模式中比我得到异常错误。

任何人都可以解释这个问题吗?

1 个答案:

答案 0 :(得分:1)

你要使用它:

XPathVar = System.String.Format(“
    /* [local-name()=’header’ and namespace-uri()=’http://namespace’]
    /* [local-name()=’detail’ and namespace-uri()=’http://namespace’]
       [position() = {0}]”, nLoopCount)

说明:以下经常选择等效集:

/*[condition1 and condition2]
/*[condition1][condition2]

但是,使用position时会出现问题。考虑一下这个表达式:

/*[condition1 and position()=1]

它选择以下两个都为真的所有元素:

  • condition1是真的
  • 元素的上下文位置等于一个

但是,这个表达式:

/*[condition1][position()=1]

... 首先选择condition1为真的所有元素,然后获取第一个这样的元素。

这是一个微妙但重要的区别。