0

使用带有 xpath 的方法 A 的模式来读取和映射无界节点(“详细信息”)正在输出多条消息。唯一的问题是在设计 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)

如果我在detail节点之后没有header节点,那么它会抛出类似于“在构造块末尾包含空值”的异常。有什么方法可以让方法 B 起作用吗?IE

这个方法有效!

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

但这不起作用并引发类似于“在构造块末尾包含空值”的异常</p>

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

如果在架构中还有其他元素或节点将 < header > 和 < detail > 分开,我会收到异常错误。

任何人都可以阐明这个问题吗?

4

1 回答 1

1

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.

于 2011-12-28T19:52:41.787 回答