XForms Everywhere

11/24/2006

Professional Web 2.0 Programming Now Available

Filed under: General — Erik Bruchez @ 2:43 am

Professional Web 2.0 Programming (Wrox)

Finally, Professional Web 2.0 Programming is now shipping from Amazon.com. I have also just received a big box with my personal copies of the book and it looks great! Read all about the book at Wrox. Also check out the excerpt, Future-Proofing Your URIs.

11/9/2006

XPath: The unordered() function, Quite an Oddity

Filed under: General — Alessandro Vernet @ 6:05 pm

There is a function in XPath which takes one parameter and that XPath engines are free to implement by just retuning that parameter. It is the unordered() function. How useful can it be?

The unordered() function takes a sequence of items as parameter and return a sequence that contain the same items, but not necessarily in the same order. The purpose of this function is not to shuffle items around, but to give an optimization hint to the XPath engine. Say you have:

/company/department/employee[@salary > 80000]

This expression returns all the employees with a salary higher than 80,000. In XPath, any expression using the path operator (”/”) must return nodes in document order. The above expression falls in that category, so if Leticia appears before Bruce in the document, Leticia must be before Bruce in the sequence of nodes returned by the expression.

If the document is stored in an XML database, you might have an index on “salary”. The XPath engine might be able to use that index to quickly retrieve the sequence of employees with a salary higher than 80,000. But because it is created based on the index, this sequence is ordered by increasing salary. To returns nodes in document order, the XPath engine needs to reorder the nodes in the sequence. If you don’t care about getting the nodes in document order, you can use the unordered() to tell the engine that this last reordering is not necessary:

unordered(/company/department/employee[@salary > 80000])

Should you use unordered() in your XPath expressions? If you think that unordered() adds clarity to your expressions, then do use it. But most likely adding unordered() will do more to clutter your XPath expressions. So you might want to check first if your engine does anything special with unordered(). If you are using a stand-alone engine, most likely unordered() is a no-op. XML databases might handle unordered() in a special way, but they are not guaranteed to do so. For instance, using unordered() in the open source eXist XML database won’t have any effect.

11/8/2006

XPath: Tuning your XPath Expressions

Filed under: General — Alessandro Vernet @ 3:51 pm

EngineWhen you write an XPath expression, you say what information you want to extract from an XML document, but you don’t tell the XPath engine how to perform that task. Consider for instance the expression:

/phonebook/person[starts-with(phone-number, '323') and last-name = 'Lee']

Imagine you are running this query on a hypothetical XML document that represents a whole phone book. The query retrieves all the persons from Hollywood (area code 323) with the last name Lee. How will the XPath engine execute this query? Let’s see a few ways in which this could happen:

  • It can go through the list of persons and start by checking the first condition first. If the first 3 digits of the phone number are 323 then it checks if the last name is “Lee”.
  • A more advanced engine might figure that the first test on the phone number is more expensive than the straight comparison with “Lee”. So it might decide that it is more efficient to do the second comparison first, and only check the first 3 digits of the area code if it already knows that the last name is “Lee”.
  • An even more advanced engine might maintain an index of the persons based on their last name. Based on this index it can quickly locate the persons with last name “Lee”. A standalone XPath engine typically wouldn’t index XML documents, but this can be certainly expected from an engine running in a database.

The XPath engine has a lot of freedom in the way it runs your XPath queries, and unless you know extremely well the engine you are using, you just can’t say that a query will run more efficiently because it is written in one way instead of another. So start by writing your queries optimizing for human readability: make them explicit and simple to understand. For instance:

  • Instead of //person use /phonebook/person, because:
    • Using /phonebook/person might be more efficient: With //person some engines will traverse every element of the document, while they would only need to go through child elements of the root element with /phonebook/person.
    • But more importantly /phonebook/person states more clearly your intension and makes your code more readable.
  • In large XPath expressions, avoid duplicating part of the expression. For instance:

    (count(/company/department[name = 'HR']/employee),
    avg(/company/department[name = 'HR']/employee/salary))

    This expression returns a sequence with the number of employees in the HR departments, and their average salary. Instead you can write it:

    for $hr in /company/department[name = 'HR']
    return (count($hr/employee), avg($hr/employee/salary))

    Unlike XQuery, XPath doesn’t have a let construct for you to declare variables. In some cases however, you can get around this by using the for construct.

Don’t try to optimize your XPath expression prematurely. Or as 37signals puts it in their book Getting Real: “It’s a Problem When It’s a Problem”. Until then just write clean and readable expressions.

11/7/2006

Future-Proofing Your URIs

Filed under: General — Erik Bruchez @ 4:10 am

Professional Web 2.0 Programming (Wrox)

Wrox has put online an excerpt from our upcoming book Professional Web 2.0 Programming. Check out Future-Proofing Your URIs!

11/5/2006

XPath: The Many Faces of a Document

Filed under: General — Alessandro Vernet @ 11:45 pm

Young Women or Old Hag?From time to time, you will come across a function in XPath that returns an XML document. If you are using XSLT 1.0 or 2.0, XPath 2.0, XQuery, or XForms, you will get to use a mix of instance(), doc(), and document(). Let’s start with instance() which you’ll find in XForms.

XForms is a technology used to create forms. The data you enter in the form is stored in one or more XML documents, which in the XForms jargon are called XForms instances. Each document in XForms has an id which can be used to retrieve the document. Here an example of a declaration of an XForms instance:

<xforms:instance id="address">
    <address>
        <street>1 Infinite Loop</street>
        <city>Cupertino</city>
        <state>California</state>
    </address>
</xforms:instance>

Assuming that the document in the instance with id address is also accessible at the URI http://www.example.org/address.xml, consider the following XPath expressions:

  • instance(’address’)
  • doc(’http://www.example.org/address.xml’)
  • document(’http://www.example.org/address.xml’)

All 3 expressions return the same “address” document. You can use first expression with instance() in XForms, the second with doc() wherever you have XPath 2.0 or XQuery expressions, and the third with document() within an XPath expression in XSLT 1.0 or 2.0 stylesheets.

While all 3 return the same “address” document, they don’t return the same node of the document: instance() returns the root element, while doc() and document() return the document node. This means that to point to the street element, you will need to write:

  • instance(’address’)/street
  • doc(’http://www.example.org/address.xml’)/address/street
  • document(’http://www.example.org/address.xml’)/address/street

Note how the name of the root element (”address”) is used with doc() and document() but not with instance(). Granted: the difference between doc()/document() on one side and instance() on the other side is trivial. But it is surprisingly easy to make a mistake when using all these functions in the same day. So keep it mind: the same document can have many faces depending on which function you use.

Orbeon PresentationServer is now Orbeon Forms

Filed under: News — Erik Bruchez @ 12:58 am

Form

We are glad to announce that Orbeon PresentationServer has a new name: Orbeon Forms.

Renaming a product is not something to be taken lightly. However we feel that:

  • Orbeon Forms better reflects the fact that forms have been the main focus of our development efforts over the last two years.

  • This new face will help potential users understand more easily what the platform can do for them.

  • Orbeon Forms is just an easier name to remember!

We are encouraged in this decision by the fact that almost all current users build complex web forms using our Ajax-based XForms engine. The name change also conveys that we plan to keep focusing on form-related capabilities in the future like we have done in the last two years.

It is important to precise the following:

  • We are not creating a separate product: Orbeon Forms is simply a new name for Orbeon PresentationServer.

  • Other XML technologies like XSLT and XML pipelines remain an important part of the platform.

  • And of course, Orbeon Forms remains an open source solution!

We will progressively migrate the web site and documentation to reflect the new name, and we can already point you to our updated home page!

11/4/2006

Two Weeks of XForms: Modularization, PDF, Dialogs, Working Group, and More

Filed under: General — Erik Bruchez @ 10:29 am
  • Modularizing Forms. We modularized the DMV Forms example by creating an XForms model with data and behavior strictly related to the “DMV Change of Address” form, and putting the common functionality in a common model. This is a first step towards a more generic forms application that you will be able to customize. We already have a nice and new form ready to be added to the application.

  • PDF Template Processor. We improved the PDF Template processor, with support for XPath 2.0, groups, and repetitions. It is now quite easy to produce PDF based on a PDF template. Now we need to write great documentation for it!

  • Dialogs. The xxforms:dialog extension is now in! You can create nice modal or modeless dialogs in the spirit of XForms.

  • Sorting Function. We implemented the exforms:sort() function defined by eXforms.

  • Insert and Delete Proposal. We made a proposal to the XForms WG to support copying and deleting multiple nodes at a time with xforms:insert and xforms:delete for 1.1.

  • Next XForms Face to Face Meeting. I booked my trip to Amsterdam for the November 15-17 XForms Working Group Face to Face meeting. As always, I am looking forward for us to do great work there.

  • New Public XForms 1.1 Draft. It’s just out, find it here. This is a “thin” spec containing the novelties of XForms 1.1. You can judge from its size that the Working Group (and in particular our editor John Boyer) hasn’t been sleeping!

Powered by WordPress