BizTalk Server General - xpath help

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > May 2006 > xpath help





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author xpath help
Michael.Goit

2006-05-15, 1:14 pm

Hello, I'm having some troubles trying to find out how to write xpath to
access an attribute of an element.. can anyone help? links to good
documenation will also be appreciated!

Here's the message I'm trying to work with. I'm trying to assign an
xmldocument variable's outerxml property to the XmlMessage attribtue below.

<ns0:Request xmlns:ns0="http://SQLUpdateMessage">
<ns0:uspSaveMessageToWorkload EntityKey="EntityKey_0"
XmlMessage="XmlMessage_1" />
</ns0:Request>
Michael.Goit

2006-05-15, 7:14 pm

Okay.. so I'm trying

xpath(spam, "/Request/uspSaveMessageToWorkload/@XmlMessage");

And it's telling me the message (spam) isn't constructed.. but this is in
the construct message shape, and this message is defined on the property
pane. arg.


"Michael.Goit" wrote:

> Hello, I'm having some troubles trying to find out how to write xpath to
> access an attribute of an element.. can anyone help? links to good
> documenation will also be appreciated!
>
> Here's the message I'm trying to work with. I'm trying to assign an
> xmldocument variable's outerxml property to the XmlMessage attribtue below.
>
> <ns0:Request xmlns:ns0="http://SQLUpdateMessage">
> <ns0:uspSaveMessageToWorkload EntityKey="EntityKey_0"
> XmlMessage="XmlMessage_1" />
> </ns0:Request>

Pabba

2006-05-15, 7:14 pm

Before assigning value to the message attribute the message needs to be
created/loaded. Make use of xml document object and load the Xml
similar to:

xmlDoc.LoadXml(@"<ns0:Request><ns0:uspSaveMessageToWorkload
EntityKey="EntotyKey_0"...
RequestMessage = xmlDoc;

and then assign values to the message attributes:

xpath(RequestMessage,"//@XmlMessage") = VarOuterXml;

For more information on Message Assignment options refer to:
http://www.objectsharp.com/Blogs/ma...11/09/1009.aspx

Hope this helps.

Regards,
Kiran Pabba

Michael.Goit

2006-05-17, 1:14 pm

Yeesh, I'm such a n00b.

Well, I'm now assigning the message fine, but I can't seem to set the
attribute, it's giving me an error.

/*
Inner exception: The XPath expression '/*[local-name()='Request' and
namespace-uri()='http://SQLUpdateMessage']/*[local-name()='uspSaveMessageToWorkload'
and namespace-uri()='http://SQLUpdateMessage'][1]/@XmlMessage' selected a
node which is not valid for property or distinguished field retrieval, or it
selected no node at all. Only text-only elements or attributes may be
selected.
*/

I shouldn't have to distinguish the field, should I? or does this mean my
xpath is wrong?

> Before assigning value to the message attribute the message needs to be
> created/loaded. Make use of xml document object and load the Xml
> similar to:
>
> xmlDoc.LoadXml(@"<ns0:Request><ns0:uspSaveMessageToWorkload
> EntityKey="EntotyKey_0"...
> RequestMessage = xmlDoc;
>
> and then assign values to the message attributes:
>
> xpath(RequestMessage,"//@XmlMessage") = VarOuterXml;
>
> For more information on Message Assignment options refer to:
> http://www.objectsharp.com/Blogs/ma...11/09/1009.aspx
>
> Hope this helps.
>
> Regards,
> Kiran Pabba
>
>

Pabba

2006-05-17, 1:14 pm

You don't need to distinguish the field. If the schema is same as what
you posted in your initial posting then the code that I posted in my
previous reply should work.
Check the link :
http://www.objectsharp.com/Blogs/ma...11/09/1009.aspx for
more information on sample code.

-Kiran Pabba

Michael.Goit

2006-05-17, 7:14 pm

thanks for your help, Pabba, this is really vexing me.

Hmm, now it's telling me "The specified node cannot be inserted as the valid
child of this node, because the specified node is the wrong type."

Here's my entire message assignment shape. (btw, how am I suppsed to put "'s
in the loadxml statement?"

---------

newDocument.LoadXml(@"<ns0:Request xmlns:ns0=""http://SQLUpdateMessage"">
<ns0:uspSaveMessageToWorkload EntityKey=""EntityKey_0""
XmlMessage=""XmlMessage_1"" /> </ns0:Request>");

SaveWorkloadMessage = newDocument;

xmlDocument = UpdateInstance;

xpath(SaveWorkloadMessage,"//@EntityKey")=
xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/Message[1]/Target[1]/Key[1]");

xpath(SaveWorkloadMessage,"//@XmlMessage") = xmlDocument.OuterXml;



Pabba

2006-05-17, 7:14 pm

Hi Michel,

Try these steps:

Step 1: Copy the xpath from Schema Editor instead typing it manually.
Assign this xpath expression return value into a variable.

varEntityKey = xpath(UpdateInstance,"string(/*[local-name()='UpdateMsg'
and namespace-uri()
='http://BRUpdateMessageSchemas.UpdateMessageSchema']/Message[1]/Target[1]/Key[1]");

Step 2: Print the variable onto Event Log Viewer to make sure data is
proper and expected.

System.Diagnostics.EventLog.WriteEntry("BizTalk","varEntityKey:
"+varEntityKey);

Repeat steps 1& 2 for your second variable.

Step 3: Load Xml Document. Only namespace value needs to be in two set
of quotes where as other attribute default values can be in a set of
double quotes.
Hint: Generate Instance for this schema using Schema Editor and then
open this in a notepad and copy the content into LoadXml(@" copyhere ")
and place another set of doubt quotes to the namespace.

newDocument.LoadXml(@"<ns0:Request
xmlns:ns0=""http://SQLUpdateMessage"">
<ns0:uspSaveMessageToWorkload EntityKey="EntityKey_0"
XmlMessage="XmlMessage_1" /> </ns0:Request>");

Step 4: Assign this newDocument object into the Message variable.

SaveWorkloadMessage = newDocument;

Step 5: Assgin variables to the Message attributes.

xpath(SaveWorkloadMessage,"//@XmlMessage") = varEntityKey;
xpath(SaveWorkloadMessage,"//@XmlMessage") = varXmlMessage; //this is
your second variable, OuterXml

For more accuracy in identifying the line where error occurred, add
System.Diagnostics.EventLog.WriteEntry("Step 1") statement after/before
each Step.

Let me know if this helps.

Regards,
Kiran Pabba

Pabba

2006-05-18, 1:15 pm

Hi Michael,

The double quotes should be the same way for attribute values as you
did for namespace i.e some default value in between two sets of double
quotes.

Regards,
Kiran Pabba

Michael.Goit

2006-05-19, 7:13 pm

Thanks Kiran...

No Dice, I got a little further.. but I'm still stuck.

Problem seems to be getting the value out of the source message, I can't get
that value into a variable.

First, the xpath that the element in the schema gives me causes an error.

Inner exception: There is an error in the XML document.
<Key xmlns=''> was not expected

so, I filled in the namespace on all the elements, and I don't get the
error, but it doesn't return a value.

I'm near the end of my rope, this shouldn't be this hard. I don't get why
the xpath that Biztalk itself gives me generates an error!

Here's the input message:
<ns0:UpdateMsg xmlns:ns0="http://BRUpdateMessageSchemas.UpdateMessageSchema">
<Message>
<Header>
<MessageId>1</MessageId>
<UpdateType>AF</UpdateType>
<CreateDate>2006-04-25T13:09:00.000-05:00</CreateDate>
</Header>
<Source>
<SourceId>1</SourceId>
<UserId>goitmic</UserId>
</Source>
<Target>
<Key>S53149561</Key>
<Complexity>true</Complexity>
</Target>
<Body>
<LegalName>Blar Blar Blar</LegalName>
</Body>
</Message>
</ns0:UpdateMsg>

---------

Cheers,
Michael

Here's the xpaths I'm using to get the element value:
//varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/Message[1]/Target[1]/Key[1]");

varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Target'
and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Key'
and namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']");


here's the whole message assignment code:
System.Diagnostics.EventLog.WriteEntry("BizTalk", "Loading SQL SP Message");
newDocument.LoadXml(@"<ns0:Request
xmlns:ns0=""http://SQLUpdateMessage""><ns0:uspSaveMessageToWorkload
EntityKey=""EntityKey_0"" XmlMessage=""XmlMessage_1"" /></ns0:Request>");

SaveWorkloadMessage = newDocument;

System.Diagnostics.EventLog.WriteEntry("BizTalk","Assigning Update Message");
xmlDocument = UpdateInstance;

System.Diagnostics.EventLog.WriteEntry("BizTalk","Setting varOuterXML");
varOuterXML = xmlDocument.OuterXml;
System.Diagnostics.EventLog.WriteEntry("BizTalk","varOuterXML: " +
varOuterXML);

System.Diagnostics.EventLog.WriteEntry("BizTalk","Setting varEntityKey");
//varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/Message[1]/Target[1]/Key[1]");

varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Target'
and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Key'
and namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']");

System.Diagnostics.EventLog.WriteEntry("BizTalk","varEntityKey: " +
varEntityKey);

System.Diagnostics.EventLog.WriteEntry("BizTalk","Assigning vars to SQL SP
Message");
xpath(SaveWorkloadMessage,"//@EntityKey") = varEntityKey;
xpath(SaveWorkloadMessage,"//@XmlMessage") = varOuterXML;

newDocument = SaveWorkloadMessage;
System.Diagnostics.EventLog.WriteEntry("BizTalk","SQLSP: " +
newDocument.OuterXml);
Greg Forsythe

2006-05-22, 7:14 am

Have you tried fully expanding the xpath:

varEntityKey = xpath(UpdateInstance,"string(/*[local-name()='UpdateMsg'
and namespace-uri()
='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
and namespace-uri()='' and position()=1]/*[local-name()='Target' and
namespace-uri()='' and position()=1]/*[local-name()='Key' and
namespace-uri()='' and position()=1]");

Greg


"Michael.Goit" <MichaelGoit@discussions.microsoft.com> wrote in message
news:5E4B10C2-3AD8-40F2-A82D-067B9C1318EF@microsoft.com...
> Thanks Kiran...
>
> No Dice, I got a little further.. but I'm still stuck.
>
> Problem seems to be getting the value out of the source message, I can't
> get
> that value into a variable.
>
> First, the xpath that the element in the schema gives me causes an error.
>
> Inner exception: There is an error in the XML document.
> <Key xmlns=''> was not expected
>
> so, I filled in the namespace on all the elements, and I don't get the
> error, but it doesn't return a value.
>
> I'm near the end of my rope, this shouldn't be this hard. I don't get why
> the xpath that Biztalk itself gives me generates an error!
>
> Here's the input message:
> <ns0:UpdateMsg
> xmlns:ns0="http://BRUpdateMessageSchemas.UpdateMessageSchema">
> <Message>
> <Header>
> <MessageId>1</MessageId>
> <UpdateType>AF</UpdateType>
> <CreateDate>2006-04-25T13:09:00.000-05:00</CreateDate>
> </Header>
> <Source>
> <SourceId>1</SourceId>
> <UserId>goitmic</UserId>
> </Source>
> <Target>
> <Key>S53149561</Key>
> <Complexity>true</Complexity>
> </Target>
> <Body>
> <LegalName>Blar Blar Blar</LegalName>
> </Body>
> </Message>
> </ns0:UpdateMsg>
>
> ---------
>
> Cheers,
> Michael
>
> Here's the xpaths I'm using to get the element value:
> //varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/Message[1]/Target[1]/Key[1]");
>
> varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
> and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Target'
> and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Key'
> and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']");
>
>
> here's the whole message assignment code:
> System.Diagnostics.EventLog.WriteEntry("BizTalk", "Loading SQL SP
> Message");
> newDocument.LoadXml(@"<ns0:Request
> xmlns:ns0=""http://SQLUpdateMessage""><ns0:uspSaveMessageToWorkload
> EntityKey=""EntityKey_0"" XmlMessage=""XmlMessage_1"" /></ns0:Request>");
>
> SaveWorkloadMessage = newDocument;
>
> System.Diagnostics.EventLog.WriteEntry("BizTalk","Assigning Update
> Message");
> xmlDocument = UpdateInstance;
>
> System.Diagnostics.EventLog.WriteEntry("BizTalk","Setting varOuterXML");
> varOuterXML = xmlDocument.OuterXml;
> System.Diagnostics.EventLog.WriteEntry("BizTalk","varOuterXML: " +
> varOuterXML);
>
> System.Diagnostics.EventLog.WriteEntry("BizTalk","Setting varEntityKey");
> //varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/Message[1]/Target[1]/Key[1]");
>
> varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
> and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Target'
> and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Key'
> and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']");
>
> System.Diagnostics.EventLog.WriteEntry("BizTalk","varEntityKey: " +
> varEntityKey);
>
> System.Diagnostics.EventLog.WriteEntry("BizTalk","Assigning vars to SQL SP
> Message");
> xpath(SaveWorkloadMessage,"//@EntityKey") = varEntityKey;
> xpath(SaveWorkloadMessage,"//@XmlMessage") = varOuterXML;
>
> newDocument = SaveWorkloadMessage;
> System.Diagnostics.EventLog.WriteEntry("BizTalk","SQLSP: " +
> newDocument.OuterXml);



Michael.Goit

2006-05-23, 1:15 pm

I tried that, and I also tried this.. both return empty strings.

varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
and namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema' and
position()=1]/*[local-name()='Target' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema' and
position()=1]/*[local-name()='Key' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema' and
position()=1]");

Should I post the shema for the update message? maybe there's something
weird with the definition.

Also, can't I just distinguish or promote (which one?) the element EntityKey
so I could use property syntax like varEntityKey = UpdateMessage.EntityKey ??



"Greg Forsythe" wrote:

> Have you tried fully expanding the xpath:
>
> varEntityKey = xpath(UpdateInstance,"string(/*[local-name()='UpdateMsg'
> and namespace-uri()
> ='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
> and namespace-uri()='' and position()=1]/*[local-name()='Target' and
> namespace-uri()='' and position()=1]/*[local-name()='Key' and
> namespace-uri()='' and position()=1]");
>
> Greg
>
>

Greg Forsythe

2006-05-24, 7:15 am

Michael,
I think I have discovered the secret and learnt something in the process.
I can use this xpath string on the sample message to retrieve the Key value
"/*[local-name()='UpdateMsg' and
namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
and namespace-uri()=''][1]/*[local-name()='Target' and
namespace-uri()=''][1]/*[local-name()='Key' and namespace-uri()=''][1]"


The original problem was not specifying a null namespace on the Message,
Target and Key nodes.
I complicated things by using the position() function inside the filter.
This evaluates to the position in the source document and Target is the
third child and has a position() of 3.
By specifying the index in a second filter you are selecting the index in
the result set produced by the first filter, there is only one Target so its
index is 1

Greg


"Michael.Goit" <MichaelGoit@discussions.microsoft.com> wrote in message
news:7F975057-D72D-48EE-A414-F8A5BF9C23DB@microsoft.com...[vbcol=seagreen]
>I tried that, and I also tried this.. both return empty strings.
>
> varEntityKey = xpath(UpdateInstance,"/*[local-name()='UpdateMsg' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema']/*[local-name()='Message'
> and namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema'
> and
> position()=1]/*[local-name()='Target' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema' and
> position()=1]/*[local-name()='Key' and
> namespace-uri()='http://BRUpdateMessageSchemas.UpdateMessageSchema' and
> position()=1]");
>
> Should I post the shema for the update message? maybe there's something
> weird with the definition.
>
> Also, can't I just distinguish or promote (which one?) the element
> EntityKey
> so I could use property syntax like varEntityKey = UpdateMessage.EntityKey
> ??
>
>
>
> "Greg Forsythe" wrote:
>


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com