Working with Expressions


XPath expressions were introduced in Chapter 7, in the discussion of expression boxes. As you probably remember, XPath is a reference and query language for XML documents and can be used to address different parts of XML schemas so that you can select the specific part that you want. In addition to referencing parts of an XML document, XPath also provides functions and operators for working with the data held in these elements.

To create an XPath expression for validation, you need to select the operator of “the expression” when creating your validation rule. This changes the data validation dialog box to show a text box that you can use to enter your expression. By default, your expression is shown as:

. = ""

The period stands for the field that you are currently working with; the equal sign and quotes have been placed there as a starting point for you to build your own expression. For example, if you want to check a Country field to see whether a value of USA has been passed, your expression would look like this:

. = "USA"

In addition to referencing a single field, you can also refer to other fields that appear on your form by using the fully qualified name. For example, if your form contains a field for ZIP code, you could check the value of this field and display an error related to your original field:

../my:zipcode = 28720

You can also use the XPath operators to perform calculations that you can use for validation. In the following example, the expression has been written to calculate a 10 percent tax rate and display an alert if this amount is greater than $100:

../my:ordertotal * .10 > 100

A key point about working with expressions is that not all the operators and functions described in Chapter 7 are valid for use with validation expressions. If you find yourself coming up against a brick wall and you can’t find the operators or functions that you need using XPath, it may be time to consider using scripting to validate your form data, as described in the next section.




How to Do Everything with Microsoft Office InfoPath 2003
How to Do Everything with Microsoft Office InfoPath 2003 (How to Do Everything)
ISBN: 0072231270
EAN: 2147483647
Year: 2006
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net