Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BizTalk XPATH "< xmlns=''> was not expected" ERROR

8 views
Skip to first unread message

bru...@ciaccess.com

unread,
Aug 24, 2006, 9:03:24 AM8/24/06
to
XPATH help please!!

What I am trying to do is, in a loop shape, extract child node data
from an incoming message so that I can use them as parameters to call a
webservice.

The incoming message schema is called
"msgGMASRequestStationCloseNotifications", and it looks like this:

<?xml version="1.0"?>
<StationCloseNotifications xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://Union.CARE.GMAS.BizTalk.schGMASRequestStationCloseNotifications">
<StationCloseNotification xmlns="">
<stationName>Bob</stationName>
<organizationName>Bob</organizationName>

<closedPeriodStart>2006-08-17T14:47:01.3387810-04:00</closedPeriodStart>

<closedPeriodEnd>2006-08-17T14:47:01.3387810-04:00</closedPeriodEnd>
<closeUser>Bob</closeUser>
</StationCloseNotifications>

In my expression shape I am using the xpath expression:

varStrStationName =
xpath(msgGMASRequestStationCloseNotifications,"/*[local-name()='StationCloseNotifications'
and
namespace-uri()='http://Union.CARE.GMAS.BizTalk.schGMASRequestStationCloseNotifications']/*[local-name()='StationCloseNotification'
and namespace-uri()='']/*[local-name()='stationName' and
namespace-uri()='']");

which gives me the event log error:

<stationName xmlns=''> was not expected.

Do you have any idea what I am missing? It is so maddening that
anywhere other than BT I can use a statement like
//StationCloseNotification[1]/stationName to get at data in any node I
want.

Thanks in advance for your help.

Gary

unread,
Aug 24, 2006, 9:37:02 AM8/24/06
to
What happens if you just take the namespace-uri part off for the station
name, does that give an error?

Jan Eliasen

unread,
Aug 26, 2006, 6:30:03 AM8/26/06
to
On 24 Aug 2006 06:03:24 -0700, bru...@ciaccess.com wrote:

>varStrStationName =
>xpath(msgGMASRequestStationCloseNotifications,"/*[local-name()='StationCloseNotifications'
>and
>namespace-uri()='http://Union.CARE.GMAS.BizTalk.schGMASRequestStationCloseNotifications']/*[local-name()='StationCloseNotification'
>and namespace-uri()='']/*[local-name()='stationName' and
>namespace-uri()='']");

How did you get this xpath expression? What I usually do is open the
schema in the schemaeditor, select the node you need, and go to the
properties. There is a property called "XPath" - copy the expression
from this and use that in your orchestration.

What about the input instance that is failing? Does that have an
xmlns="" on the stationName element?

--
eliasen, representing himself and not the company he works for.

private email: j...@eliasen.dk

Charles Young

unread,
Dec 12, 2006, 7:40:00 PM12/12/06
to
Just ran into the same problem yeaterday. Your XPath is incorrect. It is
addressing the <stationName> element in your XML. The xpath() function will
use an XPathNavigator to navigate to this element, and will then attempt to
de-serialise the node. The node should be de-serialised as an XmlNode or
XmlElement object. However, you are assigning the results of the xpath()
function to a string variable (I'm assuming this from the name which contains
'Str'). When BizTalk generates C# code for your orchestration, it converts
the call to xpath() to a line of C# that calls a method. It passes the Type
of your variable (System.String) as a parameter to this method, and that Type
is used to initialise an instance of XmlSerializer for de-serialisation.
Hence, at run time, BizTalk attempt to de-serialise an Xml element to a
string. The XmlSerializer fails saying that the content "was not expected".

A simple fix is to add "/text()" to the end of you XPath. This will return
the text content of the <stationName> element, and this will de-serialise to
a string without throwing an exception.

Jan Eliasen

unread,
Dec 13, 2006, 3:58:25 PM12/13/06
to
On Tue, 12 Dec 2006 16:40:00 -0800, Charles Young
<Charle...@discussions.microsoft.com> wrote:

>A simple fix is to add "/text()" to the end of you XPath. This will return
>the text content of the <stationName> element, and this will de-serialise to
>a string without throwing an exception.

Or, as I have just written about at
http://blog.eliasen.dk/PermaLink,guid,83d9f5af-60b4-45ad-bdc1-1e345b83772f.aspx
- use the xpath(message, "string(xpathexpression)") way of doing it.
Not sure which is the prettier? Or faster, even?

--
eliasen, representing himself and not the company he works for.

Private blog: http://blog.eliasen.dk

Private email: j...@eliasen.dk

0 new messages