What would the xpath expression be to setthe SrcFileNm attribute value from the following XML:
<ns0:Header xmlns:ns0="http://InvoiceTranslation.Schemas.W_InvoiceBcp"> <ns0:sync> <ns0:after> <ns0:W_InvoiceBcp InvNo="12345" SrcFileNm="" /> </ns0:after> </ns0:sync></ns0:Header>
I have tried:
xpath(msgMyMessage, "//*[local-name()='W_InvoiceBcp']/@[local-name()='SrcFileNm']") = "Filename.txt";
xpath(msgMyMessage, "//*@[local-name()='SrcFileNm']") = "Filename.txt";
And I get the following error:
The XPath expression '//*[local-name()='W_InvoiceBcp']/@*[local-name()='SrcFileNm']' 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 am trying to set the value inside a Message Assignement shape inside a Message Construct shape. I need to take the File.ReceiveFileName value and populate SrcFileNm. I can't promote SrcFileNm because according to the schema W_InvoiceBcp is unbounded and therefore cannot be promoted.
Greg Smith
BizTalk Admin
Greg -
Xpath is select only. You can't set a value with it.
You can select the element node, and then in a separate statement, set the attribute value.
-weak architect
Could you provide an example?
Do I have to have an XmlNode variable?
- weak architect
You can assign values using xPath according to Microsoft:
http://msdn2.microsoft.com/en-us/library/aa561906.aspx
I stand corrected. Let's see if you can achieve the objective.
Greg -Here is an xpath that works with the namespaces
/*[starts-with(local-name(), 'Header')]/*[starts-with(local-name(), 'sync')]/*[starts-with(local-name(), 'after')]/*[starts-with(local-name(), 'W_InvoiceBcp')]/@SrcFileNm
-wa
Your xPath works, but not in my orchestration. I used the following xpath demo site: http://www.futurelab.ch/xmlkurs/xpath.en.html to verify the query and it does indeed select the SrcFileNm attribute. Unfortunately so do my queries. The problem doesn't seem to be with the xpath, but something else.
I got the following error when I used your query:
The XPath expression ' /*[starts-with(local-name(), 'Header')]/*[starts-with(local-name(), 'sync')]/*[starts-with(local-name(), 'after')]/*[starts-with(local-name(), 'W_InvoiceBcp')]/@SrcFileNm' 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.
The SrcFileNm attribute has been set as a Distinguished field; I had to alter the VS generated schema so hopefully the SQL updategram still works.
I need to have the source filename written to my DB so that if an error occurs I can report it to the system admin. This would be much easier if Message Context could be accessed in maps.
g -First comment - I know there are different XML libraries that have different behavior. They are referred to as XSLT engines, but I suspect they also include the implementation of xpath. So you are definitely using MSXML in Biztalk; the website link may use another XML lib behind it. I tested your xpaths in XMLSPY with the MSXML parser and that is where they were not matching. My version is old however and either chooses v3.0 or v4.0 of MSXML. Second - we have two possible diagnoses:
1. the path failed to select a node at all (we don't suspect this)
2. it selected the node we want, but the node is not defined in the schema as "Text-Only". Can you confirm this?
3. what I have see about setting distinguished fields is that you can't set a field as distinguished if it can return more than one match, because then it doesn't know which iteration of a repeating record you want. So I presume that you changed the repeat count to allow the field to be distinguished and this is what you are referring to when you say you altered the VS generated schema?
Maybe the expression has the same problem, it thinks there can be many elements that can meet this xpath?
Hope that this chatting helps you get a solution.
xpath(msgMyMessage, /*[local-name()='Header']/*[local-name()='sync']/*[local-name()='W_InvoiceBcp']/@*[local-name()='SrcFileNm']") = "Filename.txt";
this will work!!
Enjoy!!
Manju851985
It worked for me too, thanks