Summary XML is an extremely useful data format both for storing application-specific data and for information interchange between applications. It offers a nice compromise between the simplicity and freedom of text files and rigor of databases. XML use will doubtless continue to grow on servers, desktops, and mobile devices.An important top-level decision to make is whether to use XML or binary data formats for any given communications task. XML offers great benefits, but these come at the expense of additional size and processing requirements on devices. For many uses, this overhead is justified by the benefits, and good design practices can ensure acceptable device performance. However, for data of large-enough size or when working with lower-bandwidth connections, binary alternatives should also be considered. The best thing to do is to measure the effects of using binary and XML-based communication in real-world situations and make a design decision based on achieving acceptable end-user performance. If good performance cannot be achieved by designing and tuning an efficient XML implementation, binary alternatives or changes in the communications model may need to be considered.When working with XML, it is important to consider the size of the data being processed as well as the specific purpose it is being put to. For small XML documents (for example, 20KB), it is often convenient to use an XML DOM approach where the entire XML tree is loaded into memory. The XML DOM offers random access to the document data and the easy ability to write the document back out. A significant disadvantage of the XML DOM is that it loads all of the XML data into memory at once and is therefore highly stateful. This disadvantage can become critical when working with larger documents.Forward-only XML libraries offer a good lower-level alternative appropriate for working with larger amounts of XML. The .NET Compact Framework offers the XMLReader and XMLWriter, and other frameworks may offer the SAX model for forward-only access to XML. These allow for maximum performance because they are not stateful and therefore do not need to build an in-memory tree of the data that represents the document. The XMLReader can be complex to work with if the document is complex; a state machine approach can be useful in keeping track of your position in the document's hierarchy. The XMLWriter is very easy to use for writing out XML data. Using a forward-only model may be the only reasonable approach on mobile devices when working with large amounts of XML data.Look for ways to preprocess XML data before bringing it down to a mobile device. Although it is usually not useful to round-trip data up to a server for processing, it can be very useful to preprocess XML information before bringing it down to a device. The goal of preprocessing is to transform the data into a form that is efficient to consume on devices.Chances are very good if your application stores, interchanges data, or connects to networked information sources you will end up using XML in some way or another. The advantages of a standardized text format are overwhelmingly compelling for many uses. That said, after you decide to use XML you have a great deal of additional latitude in how your application will work with it. The partition of work between servers and mobile devices, the level of abstraction and statefulness of the APIs you use, and the processing model used for working with the XML will have a large effect on the performance your end users experience. It is important to understand the options you have, what the relative strengths of these options are, and to experiment to find the right XML approach for your application. |