Use a program to modify the xsn template file of infopath

Source: Internet
Author: User
Tags xsl xsl file xslt
Reprinted: http://blog.csdn.net/yanwei100/archive/2006/12/20/1450535.aspx

Infopath template Introduction
In infopath, the template file defines the data, behavior, and display information of infopath forms. This information is not stored in a file, but stored separately.

. The main files are:
Manifest. xsf is a project file that defines which files are contained in the template, which defines the class information and data connect information. Equivalent

Project files.
The myschema. XSD, sampledata. XML, and template. xml files are datasource in the defined infopath. Myschema. XSD is a schema

Defines the data structure of datasource and the Data Type of each data node. Template. XML is an empty XML data file generated based on myschema. XSD.

If sampledata. XML is not carefully studied, the predefined data default value should be recorded.
View1.xsl defines how to display data. It is a standard XSL file.
Upgrade. XSL records version information for version comparison and version upgrade.
In addition to these basic files, if you add a script or managed code to infopathCodeSuch as C # code. These script files or compiled DLL files must also be packaged

Included in the template.

If you understand how the infopath template is defined, you can useProgramDirectly modify the template. In some cases, this is very convenient. For example, you have published

Hundreds of infopath templates have the same data links to a web service. Now, the address of web services has changed. If you manually modify the address

Quantity can be imagined.
On infopath team blogArticleDescribes how to use scripts to modify the infopath template.

Http://blogs.msdn.com/infopath/archive/2004/05/04/126147.aspx ).
The basic processing method is
Step 1: unpackage the xsn file to a temporary directory.
Step 2: Open manifest. xsf and other definition files in XML format and modify their content
Step 3: repackage the file into an xsn File

Step 1:
Download the microsoftcabinet software development kit from msdns, http://support.microsoft.com/kb/336618. It contains the unpacking and package workers we need.

. There are multiple soft-file packaging tools in the bread, which we will use extract.exeand cabarc.exe.
Command Line: extract.exe/y/e template1.xsn/L Template
Template1.xsn is the xsn file name to be unwrapped, And/L template indicates that the unwrapped file is placed under the subdirectory template.
Microsoftcabinet software development kit also provides DLL and API, you can add it to your project, and then directly call the API to complete the same operation.

Step 2: Modify the infopath Template
Here we will briefly describe the parts to be modified for each file.
1) manifest
<Xsf: xdocumentclass> the node is the root node. to modify the name of the template file, you must modify the name attribute of the node.
Name = "urn: Schemas-Microsoft-com: Office: infopath: template1:-myXSD-2006-12-17T09-42-45" in template1 is the name of the template file, just change it to your own name.
<Xsf: filenew> <xsf: initialxmldocument caption = "template1" href = "template. xml"> </xsf: initialxmldocument>
</Xsf: filenew> the Node also needs to modify the caption attribute. Note that do not modify href = "template. xml" (this is a file reference and points to template. XML ).
2) myschema
If you want to modify datasource, such as adding several data fields or groups, the main task is to modify this file. This is a standard XML Schema. You need to be familiar with the schema format. The following is a schema of infopath.
<? XML version = "1.0" encoding = "UTF-8" standalone = "no"?>
<XSD: schema targetnamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-17T09:42:45" xmlns: My = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-17T09:42:45" xmlns: XSD = "http://www.w3.org/2001/XMLSchema">
<XSD: element name = "workflowdata">
<XSD: complextype>
<XSD: sequence>
<XSD: Element ref = "My: workflowname" minoccurs = "0"/>
<XSD: Element ref = "My: workflowguid" minoccurs = "0"/>
<XSD: Element ref = "My: workflowstep1" minoccurs = "0"/>
</XSD: sequence>
<XSD: anyattribute processcontents = "LAX" namespace = "http://www.w3.org/XML/1998/namespace"/>
</XSD: complextype>
</XSD: Element>
<XSD: element name = "workflowname" type = "XSD: string"/>
<XSD: element name = "workflowguid" type = "XSD: string"/>
<XSD: element name = "workflowstep1">
<XSD: complextype>
<XSD: sequence/>
</XSD: complextype>
</XSD: Element>
</XSD: schema>
For example, you need to add an author field for workflowdata, whose data type is text. The modified content is
<? XML version = "1.0" encoding = "UTF-8" standalone = "no"?>
<XSD: schema targetnamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-17T09:42:45" xmlns: My = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-17T09:42:45" xmlns: XSD = "http://www.w3.org/2001/XMLSchema">
<XSD: element name = "workflowdata">
<XSD: complextype>
<XSD: sequence>
<XSD: Element ref = "My: workflowname" minoccurs = "0"/>
<XSD: Element ref = "My: workflowguid" minoccurs = "0"/>
<XSD: Element ref = "My: workflowauhtor" minoccurs = "0"/>
<XSD: Element ref = "My: workflowstep1" minoccurs = "0"/>
</XSD: sequence>
<XSD: anyattribute processcontents = "LAX" namespace = "http://www.w3.org/XML/1998/namespace"/>
</XSD: complextype>
</XSD: Element>
<XSD: element name = "workflowname" type = "XSD: string"/>
<XSD: element name = "workflowguid" type = "XSD: string"/>
<XSD: element name = "workflowauhtor" type = "XSD: string"/>
<XSD: element name = "workflowstep1">
<XSD: complextype>
<XSD: sequence/>
</XSD: complextype>
</XSD: Element>
</XSD: schema>

3) template
This file is relatively simple. It is a blank infopath file without data. If you have modified the datasource, you must make the same changes here.
4) sampledata
5) view1
This is an XSLT file used to format and output XML data to infopath for display. If you are familiar with XSLT and HTML, it is easy to modify this file.
Note that if you define multiple views in infopath, for example, view1 and view2, there will be two files in xsn: view1.xsl and view2.xsl.

Step 3: After all template files are modified, we can use cabarc.exe to repackage xsn
packaging command: cabarc.exe n template1.xsn template /*. *
template1.xsn is the name of the generated template file, template /*. * Indicates packaging all template files
.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.