Reputation: 1718
The first suggestion in this article - http://blog.eliasen.dk/2006/11/05/LoopingAroundElementsOfAMessage.aspx shows how to loop through an XML and and split the XML into individual elements in an orchestration.
What if I want to include the root node of the original xml in all the subsequent individual xmls? For instance, this is the xml they have:
<Employees>
<Employee title="mgr">
</Employee>
<Employee title="vp">
</Employee>
<Employee title="ceo">
</Employee>
</Employees>
what will the expression look like if I want every element output, to be enclosed in <Employees>
element:
<Employees>
<Employee title="mgr">
</Employee>
</Employees>
<Employees>
<Employee title="vp">
</Employee>
</Employees>
<Employees>
<Employee title="ceo">
</Employee>
</Employees>
The expression used in that example is this:
EmployeeMessage = xpath(InputMessage, "/*[local-name()='Employees' and namespace-uri()='']/*[local-name()='Employee' and namespace-uri()=''][" + counterStr + "]");
I'm sending this xml to a message queue system that expects the root node to be like this.
Please help. Thank you.
Update:
I found out that the root node needs to include a namespace definition for this to work. Like this:
<Employees xmlns="http://mycompany.com/hr.xsd">
<Employee title="mgr">
</Employee>
</Employees>
How do we include the namespace definition for the root node in the output?
Upvotes: 1
Views: 618
Reputation: 372
This should work:
varXmlDoc.LoadXml("<Employees xmlns='http://mycompany.com/hr.xsd'/>");
EmployeeMessage = varXmlDoc;
xpath(EmployeeMessage, "/Employees") = xpath(InputMessage, "/*[local-name()='Employees' and namespace-uri()='']/*[local-name()='Employee' and namespace-uri()=''][" + counterStr + "]");
where 'varXmlDoc' is type System.Xml.XmlDocument
Upvotes: 1