strc-xml.mkiv /size: 3070 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=strc-xml,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=XML Processing,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Structure Macros / XML Processing}
15
16% This might disappear.
17
18\unprotect
19
20\startxmlsetups xml:ctx:internal:setup
21    \xmlsetsetup{#1}{ctx:genericentry} {xml:ctx:genericentry}
22    \xmlsetsetup{#1}{ctx:sectionentry} {xml:ctx:sectionentry}
23    \xmlsetsetup{#1}{ctx:registerentry}{xml:ctx:registerentry}
24\stopxmlsetups
25
26\xmlregistersetup{xml:ctx:internal:setup}
27
28\startxmlsetups xml:ctx:genericentry
29    \xmlflush{#1}
30\stopxmlsetups
31
32\startxmlsetups xml:ctx:sectionentry
33    \xmlflush{#1}
34\stopxmlsetups
35
36\startxmlsetups xml:ctx:registerentry
37    \xmlflush{#1}
38\stopxmlsetups
39
40\protect \endinput
41
42% test.xml
43
44<?xml version='1.0' standalone='yes?>
45
46<document>
47  <section>
48    <title>Some <b>bold</b> title <b>bold <i>bold</i> oeps</b> and more</title>
49    <content>
50      <p>a paragraph of text</p>
51      <p>another paragraph of text</p>
52    </content>
53  </section>
54  <section>
55    <title>Another <b>bold</b> title <b>bold <i>bold</i> oeps</b> and more</title>
56    <content>
57      <p>a paragraph of text</p>
58      <p>another paragraph of text</p>
59    </content>
60  </section>
61</document>
62
63% test.tex
64
65\setuphead[chapter][expansion=xml]
66
67\startxmlsetups xml:demo:define:base
68    \xmlsetsetup{demo}{document|section|p|b|i}{xml:demo:*}
69\stopxmlsetups
70
71\xmlregisterdocumentsetup{demo}{xml:demo:define:base}
72
73\startxmlsetups xml:demo:document
74    \title{Contents}
75    \placelist[chapter]
76    \page
77    \xmlflush{#1}
78\stopxmlsetups
79
80\startxmlsetups xml:demo:section
81    \chapter{\xmltext{#1}{/title}}
82    \xmlfirst{#1}{/content}
83\stopxmlsetups
84
85\startxmlsetups xml:demo:p
86    \xmlflush{#1}\endgraf
87\stopxmlsetups
88
89\startxmlsetups xml:demo:b
90    \bgroup\bf\xmlflush{#1}\egroup
91\stopxmlsetups
92
93\startxmlsetups xml:demo:i
94    \bgroup\it\xmlflush{#1}\egroup
95\stopxmlsetups
96
97\starttext
98    \xmlprocessfile{demo}{oeps.xml}{}
99\stoptext
100
101% example by thomas:
102
103\startbuffer[test]
104<auth>
105  <section>
106  <title><emph>MyTitle</emph></title>
107    <content>
108     Hello world
109   </content>
110  </section>
111</auth>
112\stopbuffer
113
114\startxmlsetups xml:mysetups
115    \xmlsetsetup{\xmldocument}{auth|section|title|content|emph}{xml:*}
116\stopxmlsetups
117
118\xmlregistersetup{xml:mysetups}
119
120\startxmlsetups xml:auth
121    \xmlflush{#1}
122\stopxmlsetups
123
124\startxmlsetups xml:section
125    \xmlflush{#1}\par \midaligned{\hl[5]}
126\stopxmlsetups
127
128\startxmlsetups xml:title
129    \section{\xmlflush{#1}}
130\stopxmlsetups
131
132\startxmlsetups xml:content
133    \xmlflush{#1}\par
134\stopxmlsetups
135
136\startxmlsetups xml:emph
137    {\bgroup\em \xmlflush{#1}\egroup}
138\stopxmlsetups
139
140\setuphead
141  [section]
142  [style=normal,number=no,expansion=yes,page=yes]
143
144\starttext
145  \xmlprocessbuffer{main}{test}{}
146\stoptext
147