Help on Xpath

Viewing 2 reply threads
  • Author
    Posts
    • #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“>
      – <xs:element name=”Root“>
      – <xs:complexType>
        <xs:attribute name=”Response“ type=”xs:string“ />
        </xs:complexType>
        </xs:element>
        </xs:schema>

      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?

       

       

       

       

    • #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>&#8221;);

      Response = xmlDocVariable;

      xpath(Response, “/*[local-name()=”Root’ and namespace-uri()=’http://Test.Xpath’%5D/*%5Blocal-name()=’Response&#8217; 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 

    • #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

       

Viewing 2 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.