They are often refinements of traditional patterns. Because of their nature, XADPs can be easily and neatly expressed in the same way traditional patterns are usually presented. That is, in sections for the name, synopsis, context, solution, consequences, and related patterns. Synopsis The XMLable pattern defines a solution to managing information that is persisted as XML data, but must also be managed as meaningful objects i. Context Suppose you are writing an e-mail program that uses XML documents for the persistence of the messages.
|Genre:||Health and Food|
|Published (Last):||28 June 2010|
|PDF File Size:||8.75 Mb|
|ePub File Size:||4.64 Mb|
|Price:||Free* [*Free Regsitration Required]|
Event-driven approaches In an event-driven approach for processing XML data, a parser reads the data and notifies specialized handlers that undertake the desired actions. Note that here the term event-driven means a process that calls specific handlers when the contents of the XML document are encountered. For instance, calling endDocument when the end of the XML document is found.
The various XML parser implementations differ in their application program interfaces. For example, one parser could notify a handler of the start of an element, passing it only the name of the element and then requiring another call for the handling of attributes. Another parser could notify a handler when it finds the same start-element tag and pass it not only the name of the element, but a list of the attributes and values of that element. Another important difference between XML parsers is in which representation they use to pass data from the parser to the application: e.
The methods for handling a start-element tag with each approach would be very different and would certainly affect how you program them. Expat is a C parser developed and maintained by James Clark. It is event-driven, in the sense that it calls handlers as parts of the document are encountered by the parser. User-defined functions can be registered as handlers.
This program reads an XML document from standard input and writes a line with the name of each element to standard output, indenting child elements by one tab stop more than their parent element.
In the previous example, the userData is employed to keep track of the indentation level that should be used when printing elements and attributes to the standard output. Expat has many advantages: it is very fast and very portable. One strategy would be simply to create global functions to register with expat. Those functions can receive a pointer to the data you want to modify while reading the file e. This is a straightforward approach, but it brings several undesirable consequences into the picture: It decreases the modularity of your program.
It makes your program less cohesive i. It may ruin your OO design on a fundamental level e. All of the above will probably result in a less-maintainable program with an error prone design.
This is how wrappers like expatpp work. It was developed by Andy Dent with this basic idea: the constructor of expatpp creates an instance of an expat parser, and registers dummy functions as handlers that call the corresponding expatpp override-able methods.
For the complete code look at expatpp. When the object is constructed, the callbacks are registered as handlers to expat.
When parsing events occur, the handlers call the appropriate methods in the class. The default behavior of these methods is to do nothing, but you can override them for your own purposes. Along with the example included below, it should be enough to get you started with expatpp in an XML project. These other parsers include, most notably, the Gnome Project libxml parser by Daniel Veillard.
C++ XML [With CDROM]
Coś się nie zgadza