1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<html dir="ltr"><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="assetid" CONTENT="HV01023272"><META NAME="lcid" CONTENT="1033"><title>Structural editing in the Structural Editing developer sample form</title><link rel="stylesheet" type="text/css" href="office10.css"><script type="text/javascript" language="Javascript" src="ExpCollapse.js"></script><script type="text/javascript" language="JavaScript" src="inline.js"></script></head><body><p id="ExpandAllLine" class="ExpFav"><a href="#" onclick="ExpandAll()" onkeypress="ExpandAll()" class="DropDown"><img id="picHeader" border="0" src="expandtri.gif" alt="Show All"><span id="ExpandAll">Show All</span></a></p><h1>Structural editing in the Structural Editing developer sample form</h1><div class="ofvbanav"><span class="ofvbanavreuse" id="seealso" onclick="toggleList()" onkeypress="toggleList()"></span><span class="ofvbanavreuse" id="specifics" onclick="toggleList()" onkeypress="toggleList()"></span></div><p>Structural editing in a Microsoft Office InfoPath 2003
form occurs when a user is filling out a form, and the type of editing actions that the user performs results in a structural change to the form's underlying XML document. Structural changes involve inserting or removing <a href="#" class="glossary" onclick="AppendPopup(this,'xdxmlelement')" onkeypress="AppendPopup(this,'xdxmlelement')">elements</a> and <a href="#" class="glossary" onclick="AppendPopup(this,'xdxmlattribute')" onkeypress="AppendPopup(this,'xdxmlattribute')">attributes</a>
in the underlying XML document that the form is <a href="#" class="glossary" onclick="AppendPopup(this,'xdbind')" onkeypress="AppendPopup(this,'xdbind')">bound</a> to. For example, in the Structural Editing developer sample form, structural changes are made when a user inserts or removes items from the Parts table or the Notes bulleted list.</p><p>Structural editing controls have predetermined editing actions that can be associated with toolbar buttons and menu items in InfoPath user interface areas. The <b class="ui">Commands</b> dialog box that is available from a structural editing control's <b class="ui">Properties</b> dialog box allows you to choose which editing actions of the control are available to users, which user interface area they appear in, and the labels that are used for the associated button or menu items. The structural editing controls used in this sample form include a <a href="#" class="glossary" onclick="AppendPopup(this,'xdrepeatingtable')" onkeypress="AppendPopup(this,'xdrepeatingtable')">repeating table</a>
and a bulleted <a href="#" class="glossary" onclick="AppendPopup(this,'xdlistcontrol')" onkeypress="AppendPopup(this,'xdlistcontrol')">list</a>.</p><p>Structural editing can be implemented by using an InfoPath
structural editing control, or by using scripting code to directly manipulate the data contained in the form's underlying XML document. If the form includes a control such as a <a href="#" class="glossary" onclick="AppendPopup(this,'xdrepeatingsection')" onkeypress="AppendPopup(this,'xdrepeatingsection')">repeating section</a> that is bound to the modified (inserted or deleted) data, the data displayed in the form will be updated automatically.</p><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using controls for structural editing</a></p><div id="ExpCol" class="collapsed" border="0"><p>When you drag a structural editing control onto a form while in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a> and then <a href="#" class="glossary" onclick="AppendPopup(this,'xdbind')" onkeypress="AppendPopup(this,'xdbind')">bind</a> that control to a <a href="#" class="glossary" onclick="AppendPopup(this,'xdfield')" onkeypress="AppendPopup(this,'xdfield')">field</a> or <a href="#" class="glossary" onclick="AppendPopup(this,'xdgroup')" onkeypress="AppendPopup(this,'xdgroup')">group</a>, InfoPath
will create
an entry in the <a href="#" class="glossary" onclick="AppendPopup(this,'xdformdefinitionfilexsf')" onkeypress="AppendPopup(this,'xdformdefinitionfilexsf')">form definition (.xsf) file</a> that specifies the editing component, the XML field or group that the editing component is bound to, and the XML fragment to use when inserting new items into the associated table, section, or list.</p><p>Editing components are the InfoPath implementation of some of the controls that are used in a form, and they are set in the <b class="bterm"><a href="xsfatrcomponent.htm" id="HV01021538" lcid=" ">component</a></b> attribute of the <b class="bterm"><a href="xsfelmeditWith.htm" id="HV01021472" lcid=" ">editWith</a></b> element in the .xsf file. The editing components used by InfoPath are xField, xTextList, xCollection, xOptional, xReplace, and xImage. </p><p>In the following example from the Structural Editing developer sample form, the <b class="bterm"><a href="xsfelmediting.htm" id="HV01021471" lcid=" ">editing</a></b> element of the .xsf file contains information about the Parts table. The Parts table is implemented as a repeating table control that, in the .xsf file, corresponds to an editing component called xCollection; the xCollection editing component is listed in the <b class="bterm">component</b> attribute of the <b class="bterm">editWith</b> element. The <b class="bterm">editWith</b> element contains a <a href="#" class="glossary" onclick="AppendPopup(this,'xdchildelement')" onkeypress="AppendPopup(this,'xdchildelement')">child element</a> named <b class="bterm"><a href="xsfelmfragmentToInsert.htm" id="HV01021482" lcid=" ">fragmentToInsert</a></b>, which contains a child element named <b class="bterm"><a href="xsfelmchooseFragment.htm" id="HV01021462" lcid=" ">chooseFragment</a></b>. The <b class="bterm">chooseFragment</b> element contains the XML fragment that will be inserted in the source XML document when a user chooses to add an item to the Parts table.</p><pre><code><xsf:editing>
<xsf:xmlToEdit name="1"
item="/invoice/list/item"
container="/invoice">
<xsf:editWith caption="item" component="xCollection"
xd:autogeneration="template">
<xsf:fragmentToInsert>
<xsf:chooseFragment parent="list">
<item>
<partNumber></partNumber>
<partDescription></partDescription>
<unitPrice></unitPrice>
<quantity></quantity>
<discount>0</discount>
<netDiscount>0</netDiscount>
<total>0</total>
</item>
</xsf:chooseFragment>
</xsf:fragmentToInsert>
</xsf:editWith>
</xsf:xmlToEdit>
...
</xsf:editing>
</code></pre></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using script for structural editing</a></p><div id="ExpCol" class="collapsed" border="0"><p>Script editing in an
InfoPath form occurs when a user is filling out a form, and the types of editing actions that the user can perform are determined by custom scripting code written by form developers using
<a href="#" class="glossary" onclick="AppendPopup(this,'xdmicrosoftscripteditormse')" onkeypress="AppendPopup(this,'xdmicrosoftscripteditormse')">Microsoft Script Editor (MSE)</a>. For example, if an item in the Structural Editing developer sample form is selected in the <b class="ui">Part Catalog</b>
<a href="#" class="glossary" onclick="AppendPopup(this,'xdcustomtaskpane')" onkeypress="AppendPopup(this,'xdcustomtaskpane')"> custom task pane</a> and the <b class="ui">Add To Invoice</b> button is clicked, a new row containing part data is added to the Parts table by making a call to the InsertPartFromCatalog custom function.</p><p><b>Note</b> InfoPath supports writing script in Microsoft
<a href="#" class="glossary" onclick="AppendPopup(this,'ofVBScript')" onkeypress="AppendPopup(this,'ofVBScript')">VBScript</a> and Microsoft <a href="#" class="glossary" onclick="AppendPopup(this,'ofjscript')" onkeypress="AppendPopup(this,'ofjscript')">JScript</a>. However, you cannot mix the scripting languages used within a single form.</p><p>The InsertPartFromCatalog custom function in the Structural Editing developer sample form's script.js script file, which is shown below, contains the scripting code that is used to insert the item selected by the user into the form's source XML document. The function first obtains the
XML DOM corresponding to the <a href="#" class="glossary" onclick="AppendPopup(this,'xdformdefinitionfilexsf')" onkeypress="AppendPopup(this,'xdformdefinitionfilexsf')">form definition (.xsf) file</a> using the
<b class="bterm"><a href="xdproDOM_1.htm" id="HV01021334" lcid=" ">DOM</a></b> property of the <b class="bterm"><a href="xdobjSolution.htm" id="HV01021245" lcid=" ">Solution</a></b> object, which is accessed through the <b class="bterm"><a href="xdobjXDocument.htm" id="HV01021254" lcid=" ">XDocument</a></b> object. It then uses the standard XML DOM method <b class="bterm">selectSingleNode</b> to obtain the XML fragment to be inserted.
Next, it modifies the appropriate fields in the fragment to correspond to the selected items in the custom task pane. Finally, it inserts the fragment into the source XML document using the <b class="bterm"><a href="xdproDOM_2.htm" id="HV01032776" lcid=" ">DOM</a></b> property of the <b class="bterm">XDocument</b> object, and the standard XML DOM methods <b class="bterm">selectSingleNode</b> and <b class="bterm">appendChild</b>.</p>
<pre><code>function InsertPartFromCatalog
(strPartNumber, strPartDescription, intUnitPrice)
{
var objFragmentToInsert = null;
// Get the XML fragment to insert from the manifest.xsf.
objFragmentToInsert = XDocument.Solution.DOM
.documentElement.selectSingleNode
("//xsf:view[@name='View']//xsf:xmlToEdit[@item='/invoice/list/item']" +
"/xsf:editWith[@component='xCollection']/xsf:fragmentToInsert/
xsf:chooseFragment[@parent='list']/*[1]");
// Make a copy of the fragment and update the fields with the
// values from the catalog. Any changes to the fragment are
// made before inserting it into the document so that the
// insertion can be undone with a single Undo.
objFragmentToInsert = objFragmentToInsert.cloneNode(true);
objFragmentToInsert.selectSingleNode("partNumber").text = strPartNumber;
objFragmentToInsert.selectSingleNode("partDescription").text = strPartDescription;
objFragmentToInsert.selectSingleNode("unitPrice").text = intUnitPrice;
// Insert the XML fragment into the document.
XDocument.DOM.selectSingleNode("/invoice/list")
.appendChild(objFragmentToInsert);
}</code></pre><p>As shown in the following example, the InsertPartFromCatalog custom function is called from the <b class="ui">Part Catalog</b>
custom task pane by using the AddPartToInvoice custom function that is implemented in the code for the custom task pane. This function uses the <b class="bterm"><a href="xdproExtension.htm" id="HV01021284" lcid=" ">Extension</a></b> property of the <b class="bterm">XDocument</b> object to access the custom functions contained in the script.js script file and call the InsertPartFromCatalog custom function when a user clicks the <b class="ui">Add To Invoice</b> button.</p><pre><code>function AddPartToInvoice(objPart)
{
// Call the insertPartFromCatalog function in the business logic, passing
// the details for the part.
window.external.Window.XDocument.Extension.InsertPartFromCatalog
(objPart.PartNumber, objPart.PartDescription, objPart.UnitCost);
}</code></pre></div><script type="text/javascript" language="JScript" src="ofvbanl.js"></script><span id="ofVBAISpan" class="ofvbaispan"><iframe id="ofVBAIFrame" frameborder="0" marginheight="0" marginwidth="4" scrolling="auto" width="100%" src="../links/inconStructuralEditingInSEForm_l.htm"></iframe></span><center><a href="XMLSchemaCopyright_HV01147162.htm">©2003-2004 Microsoft Corporation. All rights reserved.</a>
Permission to copy, display and distribute this document is available at: <a
href="http://r.office.microsoft.com/r/rlidAWSContentRedir?AssetID=XT010988631033&CTT=11&Origin=HV011232471033"
target="_new">http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp</a></center></body></html>
|