~ubuntu-branches/ubuntu/jaunty/pxp/jaunty

« back to all changes in this revision

Viewing changes to examples/namespaces/README

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2002-03-27 20:47:53 UTC
  • Revision ID: james.westby@ubuntu.com-20020327204753-1lmazhm839pz62pq
Tags: upstream-1.1.4
ImportĀ upstreamĀ versionĀ 1.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
This example demonstrates namespaces: it's a tiny macro preprocessor.
 
2
You can put <macro:define> statements into your XML code, and later
 
3
expand macros by <macro:use> statements. See macro.dtd for the DTD
 
4
and sample.xml for an example in XHTML.
 
5
 
 
6
Using the preprocessor: Do
 
7
 
 
8
        ./preprocess sample.xml
 
9
 
 
10
which prints the converted text to stdout.
 
11
 
 
12
Note that the preprocessor runs in a mode which is more than
 
13
well-formedness mode and less than validating mode. The DTD 
 
14
contained in the preprocessed XML text is replaced by macro.dtd
 
15
(except the general entities which are copied), and macro.dtd
 
16
specifies that the known parts of the macro language are validated,
 
17
and that all other elements and attributes are not validated.
 
18
For example, the preprocessor does not check whether sample.xml
 
19
is valid XHTML.
 
20
 
 
21
The replacement of the DTD is performed by the ~transform_dtd
 
22
parameter of parse_document_entity (see preprocess.ml).
 
23
 
 
24
Notes to the namespaces:
 
25
 
 
26
(1) The program uses two namespaces for its own purposes:
 
27
    "http://www.ocaml-programming.de/macro" is the identifier for the
 
28
    namespace containing the <macro:define> and <macro:use> statements.
 
29
 
 
30
    "http://www.ocaml-programming.de/macro/use" is the identifier for
 
31
    the namespace containing the defined macros.
 
32
 
 
33
(2) In preprocess.ml you will find something like
 
34
 
 
35
    if node # node_type = T_element "macro:define" then ...
 
36
 
 
37
    This works even if the namespace "http://www.ocaml-programming.de/macro"
 
38
    is bound to a different prefix than "macro", because the parser
 
39
    rewrites the prefixes automatically. The DTD macro.dtd contains a
 
40
    processing instruction 
 
41
 
 
42
    <?pxp:dtd namespace prefix="macro" 
 
43
                        uri="http://www.ocaml-programming.de/macro"?>
 
44
 
 
45
    letting the parser replace all prefixes declared for the
 
46
    namespace identifier "http://www.ocaml-programming.de/macro"
 
47
    by "macro".
 
48
 
 
49
    The namespaces chapter of the manual explains the rationale
 
50
    behind that.
 
51
 
 
52
(3) You find another test
 
53
 
 
54
    node # namespace_uri = macro_use_uri
 
55
 
 
56
    where macro_use_uri is "http://www.ocaml-programming.de/macro/use".
 
57
    This is just another way to check whether an element belongs
 
58
    to a certain namespace.
 
59
 
 
60
Other comments:
 
61
 
 
62
(1) The preprocessor outputs the file always in UTF-8 encoding.
 
63
 
 
64
(2) If the input file has a DOCTYPE line, this line is reproduced
 
65
    in the output. However, the preprocessor does never output
 
66
    the internal subset of the DTD, if any.
 
67
 
 
68
(3) Although the preprocessor does not validate the input fully,
 
69
    the specified DTD is completely read in. This is necessary to
 
70
    get all the general entities.
 
71