xpath - 如何让方法 B 发挥作用?

发布于 2024-12-23 03:39:26 字数 1265 浏览 4 评论 0原文

使用方法 A 的模式和 xpath 来读取和映射无界节点(“详细信息”)可以输出多条消息。唯一的问题是设计 xsd 模式时无界节点必须始终处于序列中。 在我正在使用的消息分配对象中,我尝试读取和映射的实例 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)

如果我没有直接在 header 节点之后的 detail 节点,那么它无法抛出类似于“构造块末尾包含空值”的异常。有什么办法可以让方法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>

但这不起作用,并且如果有其他元素或节点分隔 << , 。标题>且<详情>>在模式中比我得到异常错误。

谁能阐明这个问题?

Using the Schema of Method A with xpath to read and map the unbounded node (“detail”) is working to output multiple messages. The only issue is that designing the xsd schema the unbounded node must always be in a sequence.
In the Message Assignment object I am using, the instance XPath that I am trying to read and map is

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

If I don’t have the detail node straight after the header node than it fails throwing an exception similar to ‘contained a null value at the end of the construct block’. Is there any way to get Method B to work?
i.e

This method works!

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

but this Does Not Work and throws an exception similar to ‘contained a null value at the end of the construct block’

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

if there are other elements or Nodes separating the < header > and < detail > in a schema than I get the exception error.

Can anyone shed any light on this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-12-30 03:39:26

认为你想使用这个:

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]

但是,当使用位置时,这会失败。考虑这个表达式:

/*[condition1 and position()=1]

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

  • condition1 为 true
  • 元素的上下文位置等于 1

但是,这个表达式:

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

... first 选择 condition1 为 true 的所有元素,then 选取第一个这样的元素。

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

I think that you want to use this:

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

Explanation: The following often select equivalent sets:

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

However, this breaks down when using position. Consider this expression:

/*[condition1 and position()=1]

It selects all elements for which both of the following are true:

  • condition1 is true
  • the element's context position is equal to one

However, this expression:

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

...first selects all elements for which condition1 is true and then takes the first such element.

It's a subtle but important difference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文