< Day Day Up > |
Chapter 4, "InfoPath Form Controls," describes almost all the InfoPath 2003 form controls. The expression box control gets its own chapter because it has some characteristics that are different from those of other controls. In particular, an expression box control requires you to use XPath to create XPath expressions that are associated with the control. This technique allows you to display in a form view values that aren't entered by the user, but that are derived in some way from data the user enters into the view. For example, you can automatically number an item by counting its position in an XPath node-set. Alternatively, you can sum the numbers in a column of numbers or find the average of a group of numbers . Using an Expression Box to Compose XPath ExpressionsIf you don't have much experience writing XPath code, trying to get an XPath location path exactly correct can be difficult and frustrating. You can use an InfoPath expression box to help solve your problem and get the XPath expression just as you need it to be. To illustrate the necessary technique, follow these steps:
It's important to notice that the namespace prefix for the my:field1 field is not displayed in the Select a Field or Group window, but the namespace prefix must be included in the XPath location path! This seeming discrepancy makes it easy to mistakenly select a nonexistent DOM node. If that happens, you will likely get behavior other than what you expected. For example, if you attempt to select the field1 field using the following JScript code xmlNode = XDocument.DOM.documentElement.selectSingleNode("field1"); you might expect a node to be selected. If you then use the xmlNode variable later in your JScript code, a potentially puzzling error will turn up, possibly indicating the absence of an expected object. Use the namespace prefix appropriate to your form templatethe namespace prefix my is often used automatically by InfoPath 2003, but check the namespace declarations in the script.js or script.vbs fileso the following code would be more appropriate: xmlNode = XDocument.DOM.documentElement.selectSingleNode("my:field1"); |
< Day Day Up > |