Building XML Applications
In order to build XML applications, you will need to do 4 things:
- Write or choose a DTD
- A DTD is a document type definition (template) that defines:
- What tags can go in your document.
- What tags can contain other tags.
- The number and sequence of the tags.
- The attributes your tags can have.
- The values those attributes can have
- Generate XML documents
- Your document will be invalid if you dont follow the XML tag rules.
- XML tags can"t overlap.
- You can"t leave out any end tags.
- Attribute values must be enclosed in quotes
- Tags that don"t contain any text can contain the end marker at the end of the start tag.
- The text characters (<), (>), and (") must always be represented by "character entities".
- Your document may be "Well Formed" but not "Valid" if it follows XML tag rules but does not have a DTD.
- Your document is valid only if it follows both the XML tag rules and the rules defined in their DTDs.
- Interpret XML documents (using APIs).
- Tree-based APIs
- The Document Object Model, or DOM, (standard, uses richer functions and more memory). These map an XML document into an internal tree structure, then allow an application to navigate that tree. The Document Object Model (DOM) working group at the World-Wide Web Consortium (W3C) maintains a recommended tree-based API for XML and HTML documents, and there are many such APIs from other sources.
- Event-based APIs
- An event-based API, on the other hand, reports parsing events (such as the start and end of elements) directly to the application through callbacks, and does not usually build an internal tree. The application implements handlers to deal with the different events, much like handling events in a graphical user interface.
- SAX is the best known example of such an API. The SAX API notifies you when certain events happen as it parses your document (data after this event is lost but uses less memory).
- Display XML documents.
- Simply send the document out to the browser if it can display XML.
- Use an XSL stylesheet to transform the XML into something your browser can handle.
- Do complicated processing.
- Use DOM.
- Parse the XML document.
- Write code to manipulate the DOM tree in whatever way you wish.
- Your code has complete access to the DOM and all of its methods, so you"re not bound by the limitations or design decisions of XSL.
