问题
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?
回答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.
来源:https://stackoverflow.com/questions/8660330/xpath-how-to-get-method-b-to-work