Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Modifying InfoPath manifest.xsf file from script (3/5)

Modifying InfoPath manifest.xsf file from script (3/5)

  • Comments 1

Part 3 of 5: Modifying the XSF

 

Because manifest.xsf file is just a plain xml file, the easiest way to modify it is to open it in an XML DOM, find the corresponding attributes with XPath, and replace their existing values with new data.

 

We will divide the process in two functions. The first one will be responsible for opening and saving the xml file. The second one will find and modify the attribute value.

 

The serviceURL and wsdlURL parameters are strings with values like “http://mywebservice” and “http://mywebservice?WSDL” accordingly.

 

var XsfNamespace =

"http://schemas.microsoft.com/office/infopath/2003/solutionDefinition";

var XpathToServiceUrl =

"//xsf:webServiceAdapter/xsf:operation/@serviceUrl";

var XpathToWsdlUrl =

"//xsf:webServiceAdapter/@wsdlUrl";

 

function FixupXSF(xsfInputPath, xsfOutputPath, serviceURL, wsdlURL)

{

      var Fso = new ActiveXObject ("Scripting.FileSystemObject");

      var Dom = new ActiveXObject("msxml2.domdocument.5.0");

 

      Dom.async=false;

      Dom.validateOnParse=false; // for ignoring xsi:nil errors..

      Dom.load(xsfInputPath);

      Dom.setProperty("SelectionNamespaces",

                  "xmlns:xsf='" + XsfNamespace + "'");

 

      // serviceURL

      if(serviceURL != null)

      {

            ModifyAttribute(Dom, XpathToServiceUrl, serviceURL);

      }

 

      // wsdlURL

      if(wsdlURL != null)

      {

            ModifyAttribute(Dom, XpathToWsdlUrl, wsdlURL);

      }

 

      if (Fso.FileExists(xsfOutputPath))

            Fso.DeleteFile(xsfOutputPath, true);     

      Dom.save(xsfOutputPath);

}

 

function ModifyAttribute(dom, xpath, value)

{

      var AttributeList = dom.selectNodes(xpath);

      for (;;)

      {

            var Attribute = AttributeList.nextNode();

            if(Attribute == null)

                  break;

            Attribute.nodeValue = value; 

      }

}

 

The XSF file was modified. Now we should restore our XSN and we will do it in the next part of the series.

 

Leave a Comment
  • Please add 1 and 8 and type the answer here:
  • Post
  • How to programmatically extract/manipulate/combine an InfoPath Template (XSN) file.
Page 1 of 1 (1 items)