Welcome to MSDN Blogs Sign in | Join | Help

InfoPath Team Blog

Tips and tricks to get the most out of Microsoft InfoPath

News

  • For questions, comments, and feedback please use the public newsgroup: microsoft.public.infopath
    This is provided "AS IS" with no warranties, and confers no rights. Use of included script samples and forms are subject to the terms specified in the Terms of Use.
Modifying InfoPath manifest.xsf file from script (3/5)

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.

 

Posted: Thursday, May 06, 2004 5:50 PM by infopath

Comments

Ken Brubaker said:

How to programmatically extract/manipulate/combine an InfoPath Template (XSN) file.
# January 12, 2005 5:04 PM
Anonymous comments are disabled
Page view tracker