Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Help on Xpath
- This topic has 2 replies, 1 voice, and was last updated 9 years, 10 months ago by
community-content.
-
AuthorPosts
-
-
June 10, 2008 at 8:20 AM #19887
Hi Guys,
I am working on a scenario where i have to instantiate a message and assign a new value to its property.
I have a test schema as follows
<?xml version=”1.0″ encoding=”utf-16″ ?>
– <xs:schema xmlns:b=”http://schemas.microsoft.com/BizTalk/2003“ xmlns=”http://Test.Xpath“ targetNamespace=”http://Test.Xpath“ xmlns:xs=”http://www.w3.org/2001/XMLSchema“>I added a message assignment shape and wrote following piece of code in the expression editor
Response = new System.Xml.XmlDocument();
xpath(Response, “/Root/@Response”) = “Hello”;
When i deploy the orch and run it following error is encountered
“Could not select the path /Root/@Reponse only nodes or attributes can be selected. Or no node was selected.”
What could be the problem here?
-
June 10, 2008 at 11:35 AM #19889
You need to create the Xml Instance with the node you wish to add data to. And then use fully namespace qualified xpath
xmlDocVariable.LoadXml(“<Root xmlns=’http://Test.Xpath’><Response/></Root>”);
Response = xmlDocVariable;
xpath(Response, “/*[local-name()=”Root’ and namespace-uri()=’http://Test.Xpath’%5D/*%5Blocal-name()=’Response’ and namespaceuri()=”]”) = “Hello”;
The XPath function does not change the the xml structure, just allows you to read or write from existing nodes. You can retrieve the xpath string from the schema, select the node in question and copy/paste the Instance Xpath property
-
June 11, 2008 at 10:59 AM #19899
To add to Greg’s note below, you can copy the XPath for an element or attribute from the property window of the schema (just click on the desired field, and copy the “Instance XPath” propery value. This often avoids having to build the XPath yourself.
There are also tools like Stylus Studio and XMLSpy that allow you to generate and/or test an XPath against a given XML document (there are probably freebies to download for .NET as well).
Neal
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.