Xml 2nd edition




















Publisher resources Download Example Code. Table of contents Product information. What Is RPC? SAX 2. Clark has expressed surprise that XSLT is being used in so many other applications, but it is testament to the excellent design of this standard that it has worked so well. However, you could use an XML Schema.

I usually just check well-formedness and rely on the XSLT processor to tell me when it thinks the grammar is wrong. Thanks to the enthusiasm for XSLT, there are many implementations available. Besides using a programming library or command-line tool, you could also use a web browser for its built-in XSLT transformer. Simply add a line like this to the XML document to tell the browser to transform it:.

Technology pundits have been predicting for a long time the coming of the paperless office. All data would be stored on computer, read on monitors and passed around through the network. But the truth is, people use paper now more than ever. For reading a long document, there is still no substitute for paper. Therefore, XML has had to embrace print. Formatting for print begins with a transformation.

Your XML document, which is marked up for describing structure and information, says nothing about the appearance. It needs to be converted into a presentational format that describes how things should look: typefaces, colors, positions on the page, and so on.

The trick is how to get from your XML to one of these formats. You could, theoretically, write a transformation stylesheet to mutate your XML into PostScript, but this will give you nightmares and a head full of gray hairs.

Any transformation stylesheet you write will require such intimate knowledge of byzantine rules and obscure syntactic conventions that it will quickly lead to madness. Fortunately, somebody has had the brilliant idea to develop a formatting language based on plain English, using XML for its structural markup.

Best of all, it works wonderfully with XSLT. The whole thing runs as a pipeline, very smooth and clean. The elements that start with xsl : are XSLT commands and elements that start with fo : are formatting object tags. After running the telegram example through FOP with this stylesheet, Figure is the result.

When all else fails, you can write a program. Parsers are the front line for any program that works with XML. There are several strategies available, depending on how you want to use the XML. The parser reads the XML and calls on your program to handle each new item in the stream, hence the name stream processing.

If you need to access information out of order, you have to save it in memory. The parser typically reads in a document and stores it in a data structure. The structure resembles a tree, with the outermost element as the root, and its contents branching out to the innermost text which are like leaves.

It requires more memory and computation, but is often the most convenient way to accomplish a task. Developers have come up with standard programming interfaces for each of these techniques. This allows programs to use interchangeable modules, greatly enhancing flexibility. This is illustrated in Figure It describes a wide variety of accessor methods for objects containing parts of an XML document.

With DOM, you can crawl over all the elements in a document in any order, rearrange them, add or subtract parts, and extract any data you want. Many web browsers have built-in support for DOM, allowing you to select and repackage information from a server using Java or JavaScript.

SOAP is a way for browsers to trade complex data packages with servers. Unlike HTML, which marks up data based on appearance, it describes its contents as data objects with types, names, and values, which is much more handy for computer processing.

Extracting data from deep inside a document is a common task for developers. XPath is a shorthand for locating a point inside an XML document. Skip to main content. Start your free trial. How Do I Get Started? Authoring Documents. Table Comparison of XML editor features. Viewing Documents. Amaya Amaya is a project by the W3C to demonstrate technologies working together. Named Patterns 4. Recursive definitions 4. Aggregate definitions 4. Modularity 4.

External references 4. Nested grammars 4. Merging grammars 4. Overriding imported definitions 4. CensusML Example 4. Overview 4. Abstract Rules 4. Schemas Compared 5. Stylesheets 5. Why We Need Them 5. How They Work 5. Applying properties 5. Client and server-side processing 5. Cascading styles 5. Associating a stylesheet to a document 5. Limitations 5. CSS Basics 5. The CSS Specification 5. Syntax 5. Matching Properties to Elements 5.

Property Inheritance 5. Combining Stylesheets 5. Rule Matching 5. Elements 5. Attributes 5. Contextual Selection 5. Ancestry 5. Position 5. Resolving Property Conflicts 5. Properties 5. Inheritance 5.

Units of Measurement 5. Display Types 5. Blockish Properties 5. Margins 5. Borders 5. Padding 5. Alignment and indentation 5. Text Properties 5. Font family 5. Font size 5. Line height and font size adjustment 5. Font style and weight 5. Color 5. Generated Text 5. Counters 5. Examples 6. XPath and XPointer 6. Nodes and Trees 6. Node Types 6. Trees and Subtrees 6. Finding Nodes 6. XPath Expressions 6.

Boolean Expressions 6. Node Set Expressions 6. Numeric Expressions 6. String Expressions 6. XPointer 6. Syntax 6. Schemes and chained xpointers 6. Shorthand pointers 6. Points 6. Character Escaping 6. XPointer Functions 6. Constructing ranges 6. Ranges from points and nodes 6. Ranges from strings 6. Finding range endpoints 6. Returning points from documents 7. Transformation with XSLT 7. History 7. Concepts 7. Running Transformations 7.

The stylesheet Element 7. Templates 7. Matching Nodes 7. Resolving Conflicts Among Rules 7. It looks like this:. This is a processing instruction , not an element. Figure shows a screenshot of how it looks in Safari version 1. CSS is limited to cases where the output text will be in the same order as the input data.

It would not be so useful if you wanted to show only an excerpt of the data, or if you wanted it to appear in a different order from the data. For example, suppose you collected a lot of phone numbers in an XML file and then wanted to generate a telephone directory from that. A more powerful technique is to transform the XML. Transformation is a process that breaks apart an XML document and builds a new one. The new document may or may not use the same markup language in fact, XML is only one option; you can transform XML into any kind of text.

It requires a transformation instruction which happens to be called a stylesheet not to be confused with a CSS stylesheet. The process looks like the diagram in Figure A popular use of transformations is to change a non-presentation XML data file into a format that combines data with presentational information.

Typically, this format will throw away semantic information in favor of device-specific and highly presentational descriptions. For example, elements that distinguish between filenames and emphasized text would be replaced with tags that turn on italic formatting. Once you lose the semantic information, it is much harder to transform the document back to the original data-specific format. That is okay, because what we get from presentational formats is the ability to render a pleasing view on screen or printed page.

There are many presentational formats. Public domain varieties include the venerable troff, which dates back to the first Unix system, and T E X, which is still popular in universities. There are even some XML formats that can be included in this domain. XHTML is rather generic and presentational for narrative documents. SVG, a graphics description language, is another format you could transform to from a more semantic language.

Figure shows how it looks in a browser. It is not so good for print media, however. HTML was never designed to handle the complex formatting of printed documents, with headers and footers, multiple columns, and page breaks.

For that, you would want to transform into a richer format such as PDF. A direct transformation into PDF is not so easy to do, however. It requires extensive knowledge of the PDF specification which is huge and difficult, and much of the content is compressed.

A better solution is to transform your XML into an intermediate format, one that is generic and easy for humans to understand. A formatting object is an abstract representation for a portion of a formatted page. You use XSLT to map elements to formatting objects, and an XSL formatter turns the formatting objects into pages, paragraphs, graphics, and other presentational components.

The process is illustrated in Figure This intermediate file is then fed into the XSL formatter which processes it into a presentational format, such as PDF. The beauty of this system is that it is modular.



0コメント

  • 1000 / 1000