Extracting XML document in XML node from WCF-SQL message using body path expression











up vote
0
down vote

favorite












I am receiving a message from an SQL server in WCF-SQL adapter. In this message there is an XML node, which contains a fully formatted XML document as a string. What I need, is to extract only this document, ignoring the rest of the body, so that it can be processed further by a pipeline.



I've tried a bunch of xPath expressions in the "body path expression" input field in the config settings on the adapter, but none of them seems to work the way i expect.



Some xPath strings I've tried:



    /Polling/PolledData[1]/*[namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data' and local-name()='DataSet'][1]/*[namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1' and local-name()='diffgram'][1]/*[namespace-uri()='' and local-name()='NewDataSet'][1]/*[namespace-uri()='' and local-name()='NewTable'][1]/*[namespace-uri()='' and local-name()='msgbody'][1]

/*[local-name()='Polling']/*[local-name()='PolledData']/*[local-name()='DataSet']/*[local-name()='diffgram']/*[local-name()='NewDataSet']/*[local-name()='NewTable']/*[local-name()='msgbody']

/Polling/PolledData/DataSet/diffgr:diffgram/NewDataSet/NewTable/msgbody

//*[msgbody]/text()


The body of the XML document I receive is structured like so, with the XML node I am trying to extract content from at the end:



<Polling xmlns="http://schemas.microsoft.com/Sql/2008/05/Polling/">
<PolledData>
<DataSet xmlns="http://schemas.datacontract.org/2004/07/System.Data">
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NewTable">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="conversationID" type="xs:string"/>
<xs:element minOccurs="0" name="hostUTC" type="xs:dateTime"/>
<xs:element minOccurs="0" name="msgType" type="xs:string"/>
<xs:element minOccurs="0" name="acknowledgment" type="xs:string"/>
<xs:element minOccurs="0" name="sendLog" type="xs:string"/>
<xs:element minOccurs="0" name="msgFormat" type="xs:string"/>
<xs:element minOccurs="0" name="msgbody" type="xs:string"/>
<xs:element minOccurs="0" name="fromID" type="xs:string"/>
<xs:element minOccurs="0" name="toID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<NewTable>
<conversationID>b4327577-14d1-478d-9e22-027683c0c5f9</conversationID>
<hostUTC>2018-11-19T13:17:07.03Z</hostUTC>
<msgType>INVOIC</msgType>
<msgFormat>oioUBL</msgFormat>
<msgbody>&lt;Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


I'm unsure how to properly write the correct xPath to this node. Reading the documention on MS docs seems to indicate that I need to use the local-name syntax. I think my problem lies in the use of namespaces in the received XML, but I don't know how to include these in the xPath.










share|improve this question






















  • Did you try to just get the whole message into biztalk without setting the body xpath. Then manually test your body xpath?
    – r3verse
    Nov 20 at 16:14















up vote
0
down vote

favorite












I am receiving a message from an SQL server in WCF-SQL adapter. In this message there is an XML node, which contains a fully formatted XML document as a string. What I need, is to extract only this document, ignoring the rest of the body, so that it can be processed further by a pipeline.



I've tried a bunch of xPath expressions in the "body path expression" input field in the config settings on the adapter, but none of them seems to work the way i expect.



Some xPath strings I've tried:



    /Polling/PolledData[1]/*[namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data' and local-name()='DataSet'][1]/*[namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1' and local-name()='diffgram'][1]/*[namespace-uri()='' and local-name()='NewDataSet'][1]/*[namespace-uri()='' and local-name()='NewTable'][1]/*[namespace-uri()='' and local-name()='msgbody'][1]

/*[local-name()='Polling']/*[local-name()='PolledData']/*[local-name()='DataSet']/*[local-name()='diffgram']/*[local-name()='NewDataSet']/*[local-name()='NewTable']/*[local-name()='msgbody']

/Polling/PolledData/DataSet/diffgr:diffgram/NewDataSet/NewTable/msgbody

//*[msgbody]/text()


The body of the XML document I receive is structured like so, with the XML node I am trying to extract content from at the end:



<Polling xmlns="http://schemas.microsoft.com/Sql/2008/05/Polling/">
<PolledData>
<DataSet xmlns="http://schemas.datacontract.org/2004/07/System.Data">
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NewTable">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="conversationID" type="xs:string"/>
<xs:element minOccurs="0" name="hostUTC" type="xs:dateTime"/>
<xs:element minOccurs="0" name="msgType" type="xs:string"/>
<xs:element minOccurs="0" name="acknowledgment" type="xs:string"/>
<xs:element minOccurs="0" name="sendLog" type="xs:string"/>
<xs:element minOccurs="0" name="msgFormat" type="xs:string"/>
<xs:element minOccurs="0" name="msgbody" type="xs:string"/>
<xs:element minOccurs="0" name="fromID" type="xs:string"/>
<xs:element minOccurs="0" name="toID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<NewTable>
<conversationID>b4327577-14d1-478d-9e22-027683c0c5f9</conversationID>
<hostUTC>2018-11-19T13:17:07.03Z</hostUTC>
<msgType>INVOIC</msgType>
<msgFormat>oioUBL</msgFormat>
<msgbody>&lt;Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


I'm unsure how to properly write the correct xPath to this node. Reading the documention on MS docs seems to indicate that I need to use the local-name syntax. I think my problem lies in the use of namespaces in the received XML, but I don't know how to include these in the xPath.










share|improve this question






















  • Did you try to just get the whole message into biztalk without setting the body xpath. Then manually test your body xpath?
    – r3verse
    Nov 20 at 16:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am receiving a message from an SQL server in WCF-SQL adapter. In this message there is an XML node, which contains a fully formatted XML document as a string. What I need, is to extract only this document, ignoring the rest of the body, so that it can be processed further by a pipeline.



I've tried a bunch of xPath expressions in the "body path expression" input field in the config settings on the adapter, but none of them seems to work the way i expect.



Some xPath strings I've tried:



    /Polling/PolledData[1]/*[namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data' and local-name()='DataSet'][1]/*[namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1' and local-name()='diffgram'][1]/*[namespace-uri()='' and local-name()='NewDataSet'][1]/*[namespace-uri()='' and local-name()='NewTable'][1]/*[namespace-uri()='' and local-name()='msgbody'][1]

/*[local-name()='Polling']/*[local-name()='PolledData']/*[local-name()='DataSet']/*[local-name()='diffgram']/*[local-name()='NewDataSet']/*[local-name()='NewTable']/*[local-name()='msgbody']

/Polling/PolledData/DataSet/diffgr:diffgram/NewDataSet/NewTable/msgbody

//*[msgbody]/text()


The body of the XML document I receive is structured like so, with the XML node I am trying to extract content from at the end:



<Polling xmlns="http://schemas.microsoft.com/Sql/2008/05/Polling/">
<PolledData>
<DataSet xmlns="http://schemas.datacontract.org/2004/07/System.Data">
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NewTable">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="conversationID" type="xs:string"/>
<xs:element minOccurs="0" name="hostUTC" type="xs:dateTime"/>
<xs:element minOccurs="0" name="msgType" type="xs:string"/>
<xs:element minOccurs="0" name="acknowledgment" type="xs:string"/>
<xs:element minOccurs="0" name="sendLog" type="xs:string"/>
<xs:element minOccurs="0" name="msgFormat" type="xs:string"/>
<xs:element minOccurs="0" name="msgbody" type="xs:string"/>
<xs:element minOccurs="0" name="fromID" type="xs:string"/>
<xs:element minOccurs="0" name="toID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<NewTable>
<conversationID>b4327577-14d1-478d-9e22-027683c0c5f9</conversationID>
<hostUTC>2018-11-19T13:17:07.03Z</hostUTC>
<msgType>INVOIC</msgType>
<msgFormat>oioUBL</msgFormat>
<msgbody>&lt;Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


I'm unsure how to properly write the correct xPath to this node. Reading the documention on MS docs seems to indicate that I need to use the local-name syntax. I think my problem lies in the use of namespaces in the received XML, but I don't know how to include these in the xPath.










share|improve this question













I am receiving a message from an SQL server in WCF-SQL adapter. In this message there is an XML node, which contains a fully formatted XML document as a string. What I need, is to extract only this document, ignoring the rest of the body, so that it can be processed further by a pipeline.



I've tried a bunch of xPath expressions in the "body path expression" input field in the config settings on the adapter, but none of them seems to work the way i expect.



Some xPath strings I've tried:



    /Polling/PolledData[1]/*[namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data' and local-name()='DataSet'][1]/*[namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1' and local-name()='diffgram'][1]/*[namespace-uri()='' and local-name()='NewDataSet'][1]/*[namespace-uri()='' and local-name()='NewTable'][1]/*[namespace-uri()='' and local-name()='msgbody'][1]

/*[local-name()='Polling']/*[local-name()='PolledData']/*[local-name()='DataSet']/*[local-name()='diffgram']/*[local-name()='NewDataSet']/*[local-name()='NewTable']/*[local-name()='msgbody']

/Polling/PolledData/DataSet/diffgr:diffgram/NewDataSet/NewTable/msgbody

//*[msgbody]/text()


The body of the XML document I receive is structured like so, with the XML node I am trying to extract content from at the end:



<Polling xmlns="http://schemas.microsoft.com/Sql/2008/05/Polling/">
<PolledData>
<DataSet xmlns="http://schemas.datacontract.org/2004/07/System.Data">
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NewTable">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="conversationID" type="xs:string"/>
<xs:element minOccurs="0" name="hostUTC" type="xs:dateTime"/>
<xs:element minOccurs="0" name="msgType" type="xs:string"/>
<xs:element minOccurs="0" name="acknowledgment" type="xs:string"/>
<xs:element minOccurs="0" name="sendLog" type="xs:string"/>
<xs:element minOccurs="0" name="msgFormat" type="xs:string"/>
<xs:element minOccurs="0" name="msgbody" type="xs:string"/>
<xs:element minOccurs="0" name="fromID" type="xs:string"/>
<xs:element minOccurs="0" name="toID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<NewTable>
<conversationID>b4327577-14d1-478d-9e22-027683c0c5f9</conversationID>
<hostUTC>2018-11-19T13:17:07.03Z</hostUTC>
<msgType>INVOIC</msgType>
<msgFormat>oioUBL</msgFormat>
<msgbody>&lt;Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


I'm unsure how to properly write the correct xPath to this node. Reading the documention on MS docs seems to indicate that I need to use the local-name syntax. I think my problem lies in the use of namespaces in the received XML, but I don't know how to include these in the xPath.







xml wcf xpath biztalk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 10:28









Leth

459616




459616












  • Did you try to just get the whole message into biztalk without setting the body xpath. Then manually test your body xpath?
    – r3verse
    Nov 20 at 16:14


















  • Did you try to just get the whole message into biztalk without setting the body xpath. Then manually test your body xpath?
    – r3verse
    Nov 20 at 16:14
















Did you try to just get the whole message into biztalk without setting the body xpath. Then manually test your body xpath?
– r3verse
Nov 20 at 16:14




Did you try to just get the whole message into biztalk without setting the body xpath. Then manually test your body xpath?
– r3verse
Nov 20 at 16:14












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Your first XPath was nearly right, except you were missing the namespaces from it for the first two nodes.



Also the [1]'s in your first your XPath examples are necessary unless there are multiple nodes and you wish to select the first one.



The correct Xpath would be



/*[local-name()='Polling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='PolledData' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']
/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']
/*[local-name()='NewDataSet' and namespace-uri()='']
/*[local-name()='NewTable' and namespace-uri()='']
/*[local-name()='msgbody' and namespace-uri()='']


But I you might still have an issue as it looks like the rest of your payload has been escaped, e.g. the < is a &lt;






share|improve this answer























  • Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
    – Leth
    Nov 22 at 9:43











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390957%2fextracting-xml-document-in-xml-node-from-wcf-sql-message-using-body-path-express%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Your first XPath was nearly right, except you were missing the namespaces from it for the first two nodes.



Also the [1]'s in your first your XPath examples are necessary unless there are multiple nodes and you wish to select the first one.



The correct Xpath would be



/*[local-name()='Polling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='PolledData' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']
/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']
/*[local-name()='NewDataSet' and namespace-uri()='']
/*[local-name()='NewTable' and namespace-uri()='']
/*[local-name()='msgbody' and namespace-uri()='']


But I you might still have an issue as it looks like the rest of your payload has been escaped, e.g. the < is a &lt;






share|improve this answer























  • Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
    – Leth
    Nov 22 at 9:43















up vote
1
down vote



accepted










Your first XPath was nearly right, except you were missing the namespaces from it for the first two nodes.



Also the [1]'s in your first your XPath examples are necessary unless there are multiple nodes and you wish to select the first one.



The correct Xpath would be



/*[local-name()='Polling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='PolledData' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']
/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']
/*[local-name()='NewDataSet' and namespace-uri()='']
/*[local-name()='NewTable' and namespace-uri()='']
/*[local-name()='msgbody' and namespace-uri()='']


But I you might still have an issue as it looks like the rest of your payload has been escaped, e.g. the < is a &lt;






share|improve this answer























  • Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
    – Leth
    Nov 22 at 9:43













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Your first XPath was nearly right, except you were missing the namespaces from it for the first two nodes.



Also the [1]'s in your first your XPath examples are necessary unless there are multiple nodes and you wish to select the first one.



The correct Xpath would be



/*[local-name()='Polling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='PolledData' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']
/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']
/*[local-name()='NewDataSet' and namespace-uri()='']
/*[local-name()='NewTable' and namespace-uri()='']
/*[local-name()='msgbody' and namespace-uri()='']


But I you might still have an issue as it looks like the rest of your payload has been escaped, e.g. the < is a &lt;






share|improve this answer














Your first XPath was nearly right, except you were missing the namespaces from it for the first two nodes.



Also the [1]'s in your first your XPath examples are necessary unless there are multiple nodes and you wish to select the first one.



The correct Xpath would be



/*[local-name()='Polling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='PolledData' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Polling/']
/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']
/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']
/*[local-name()='NewDataSet' and namespace-uri()='']
/*[local-name()='NewTable' and namespace-uri()='']
/*[local-name()='msgbody' and namespace-uri()='']


But I you might still have an issue as it looks like the rest of your payload has been escaped, e.g. the < is a &lt;







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 1:31

























answered Nov 21 at 0:55









Dijkgraaf

7,19872744




7,19872744












  • Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
    – Leth
    Nov 22 at 9:43


















  • Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
    – Leth
    Nov 22 at 9:43
















Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
– Leth
Nov 22 at 9:43




Thank you so much! This returned the expected content from the node. Biztalk seems to automatically convert the escaped characters to the corresponding XML tags.
– Leth
Nov 22 at 9:43


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390957%2fextracting-xml-document-in-xml-node-from-wcf-sql-message-using-body-path-express%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen