summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/strc-xml.mkiv
blob: 3f9b4ef811d5026e83ab15ac6fef1a7eb64a02a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
%D \module
%D   [       file=strc-xml,
%D        version=2008.10.20,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=XML Processing,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Structure Macros / XML Processing}

% This might disappear.

\unprotect

\startxmlsetups xml:ctx:internal:setup
    \xmlsetsetup{#1}{ctx:genericentry} {xml:ctx:genericentry}
    \xmlsetsetup{#1}{ctx:sectionentry} {xml:ctx:sectionentry}
    \xmlsetsetup{#1}{ctx:registerentry}{xml:ctx:registerentry}
\stopxmlsetups

\xmlregistersetup{xml:ctx:internal:setup}

\startxmlsetups xml:ctx:genericentry
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:ctx:sectionentry
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:ctx:registerentry
    \xmlflush{#1}
\stopxmlsetups

\protect \endinput

% test.xml

<?xml version='1.0' standalone='yes?>

<document>
  <section>
    <title>Some <b>bold</b> title <b>bold <i>bold</i> oeps</b> and more</title>
    <content>
      <p>a paragraph of text</p>
      <p>another paragraph of text</p>
    </content>
  </section>
  <section>
    <title>Another <b>bold</b> title <b>bold <i>bold</i> oeps</b> and more</title>
    <content>
      <p>a paragraph of text</p>
      <p>another paragraph of text</p>
    </content>
  </section>
</document>

% test.tex

\setuphead[chapter][expansion=xml]

\startxmlsetups xml:demo:define:base
    \xmlsetsetup{demo}{document|section|p|b|i}{xml:demo:*}
\stopxmlsetups

\xmlregisterdocumentsetup{demo}{xml:demo:define:base}

\startxmlsetups xml:demo:document
    \title{Contents}
    \placelist[chapter]
    \page
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:section
    \chapter{\xmltext{#1}{/title}}
    \xmlfirst{#1}{/content}
\stopxmlsetups

\startxmlsetups xml:demo:p
    \xmlflush{#1}\endgraf
\stopxmlsetups

\startxmlsetups xml:demo:b
    \bgroup\bf\xmlflush{#1}\egroup
\stopxmlsetups

\startxmlsetups xml:demo:i
    \bgroup\it\xmlflush{#1}\egroup
\stopxmlsetups

\starttext
    \xmlprocessfile{demo}{oeps.xml}{}
\stoptext

% example by thomas:

\startbuffer[test]
<auth>
  <section>
  <title><emph>MyTitle</emph></title>
    <content>
     Hello world
   </content>
  </section>
</auth>
\stopbuffer

\startxmlsetups xml:mysetups
    \xmlsetsetup{\xmldocument}{auth|section|title|content|emph}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetups}

\startxmlsetups xml:auth
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:section
    \xmlflush{#1}\par \midaligned{\hl[5]}
\stopxmlsetups

\startxmlsetups xml:title
    \section{\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups xml:content
    \xmlflush{#1}\par
\stopxmlsetups

\startxmlsetups xml:emph
    {\bgroup\em \xmlflush{#1}\egroup}
\stopxmlsetups

\setuphead
  [section]
  [style=normal,number=no,expansion=yes,page=yes]

\starttext
  \xmlprocessbuffer{main}{test}{}
\stoptext