File: xmlproc-dtd-doco.html

package info (click to toggle)
python-xml 0.4.19981014-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,124 kB
  • ctags: 3,099
  • sloc: ansic: 9,075; python: 8,150; xml: 7,940; makefile: 84; sh: 41
file content (254 lines) | stat: -rw-r--r-- 8,629 bytes parent folder | download
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE>Documentation: xmlproc DTD APIs</TITLE>
  <META NAME="Author"    CONTENT="Lars Marius Garshol">
  <META NAME="Generator" CONTENT="Homemade (http://birk105.studby.uio.no/hovedfag/pilot.html)">
  <META NAME="Description" CONTENT="This is the detailed documentation of the APIs used in the xmlproc XML parser to access DTD information.">
  <LINK REL=StyleSheet HREF="../../artikler/artikler.css" TYPE="text/css" MEDIA=screen>
</HEAD>

<BODY>

<DIV CLASS=partof>
<A HREF="xmlproc-doco.html">Documentation: The xmlproc APIs</A>.
</DIV>

<H1>Documentation: xmlproc DTD APIs</H1>

<H2>Working with DTDs</H2>

<H3>Accessing DTD information</H3>

<P>
DTD information is only available from the validating parser, which
implements a get_dtd method, which can be used to get an object
conforming to the <A HREF="#DTD">DTD interface</A>, containing all
information about the DTD.
</P>

<H3>Parsing a DTD without parsing a document</H3>

<P>
This functionality is not yet supported. In a future version of
xmlproc the DTD parser will be made a separate module and possibly
even distributed separately. If you want to do this now you should
read the source code.
</P>

<H2>List of interfaces</H2>

<P>
These are the interfaces used to discover information about the DTD of
the parsed document:
</P>

<UL>
  <LI><A HREF="#DTD">The DTD interface</A>.
  <LI><A HREF="#ElementType">The ElementType interface</A>.
  <LI><A HREF="#Attribute">The Attribute interface</A>.
  <LI><A HREF="#Entity">The Entity interface</A>.
  <LI><A HREF="#DTDConsumer">The DTDConsumer interface</A>.
</UL>

<H2><A NAME="DTD">The DTD interface</A></H2>

<P>
This is the interface of the object that holds information about the
DTD of the current document. This object can be queried to discover
information about the DTD.
</P>

<DL>
  <DT><CODE>def resolve_pe(self,name):</CODE>
  <DD>Returns the entity object (either InternalEntity or
  ExternalEntity) of the parameter entity with the given name. If no
  parameter entity with this name has been declared a KeyError is
  thrown.
  
  <DT><CODE>def resolve_ge(self,name):</CODE>
  <DD>Returns the entity object (either InternalEntity or
  ExternalEntity) of the general entity with the given name. If no
  general entity with this name has been declared a KeyError is
  thrown.

  <DT><CODE>def get_elem(self,name):</CODE>
  <DD>Returns the <A HREF="#ElementType">element object</A> of the
  element with the given
  name.  Throws a KeyError if no such element has been declared.
  
  <DT><CODE>def get_root_elem(self):</CODE>
  <DD>Returns the name of the element declared as the root element (as
  a string).
  
  <DT><CODE>def get_notation(self,name):</CODE>
  <DD>Returns the notation object of the given notation. If no such
  notation has been declared a KeyError is thrown. 

  <DT><CODE>def get_elements(self):</CODE>
  <DD>Returns a list of all declared element names.
</DL>

<H2><A NAME="ElementType">The ElementType interface</A></H2>

<P>
This class encapsulates information about an element type.
</P>

<DL>
  <DT><CODE>def get_name(self):</CODE>
  <DD>Returns the name of the element type.

  <DT><CODE>def get_attr_list(self):</CODE>
  <DD>Returns a list of the names of the declared attributes for this
  element (as strings). 
  
  <DT><CODE>def get_attr(self,name):</CODE>
  <DD>Returns the attribute object of the given attribute or throws a
  KeyError if none has been declared.
  
  <DT><CODE>def get_start_state(self):</CODE>
  <DD>Returns the start state of the content model of the element. (No
  guarantees is made as to the type of this value.)
  
  <DT><CODE>def final_state(self,state):</CODE>
  <DD>Returns true if the given state (as returned by get_start_state
  or next_state) is a final state, ie: one in which the element is
  allowed to end.
  
  <DT><CODE>def next_state(self,state,elem_name):</CODE>
  <DD>Returns the next state of the element when the an element with
  the given name is encountered in the given state. Character data is
  represented as the element name '#PCDATA'.  
</DL>

<H2><A NAME="Attribute">The Attribute interface</A></H2>

<P>
This class encapsulates information about an attribute.
</P>

<DL>
  <DT><CODE>def validate(self,value,err):</CODE>
  <DD>Takes an attribute value ('value') and an ErrorHandler ('err')
  and validates the attribute value for correctness, reporting errors
  to 'err'.
  
  <DT><CODE>def get_name(self):</CODE>
  <DD>Returns the name of the attribute.
  
  <DT><CODE>def get_type(self):</CODE>
  <DD>Returns the declared type of the attribute. (ID, CDATA etc.)
  
  <DT><CODE>def get_decl(self):</CODE>
  <DD>Returns the default declaration of the attribute. (#IMPLIED,
  #REQUIRED, #FIXED or #DEFAULT.)
  
  <DT><CODE>def get_default(self):</CODE>
  <DD>Return the default value of the attribute, or None if none has
  been declared.  
</DL>

<H2><A NAME="Entity">The Entity interface</A></H2>

<P>
This class encapsulates information about entities. It is implemented
by two classes: InternalEntity and ExternalEntity. InternalEntity only
implements a subset of the interface.
</P>

<DL>
  <DT><CODE>def is_internal(self):</CODE>
  <DD>True if the entity is internal, false otherwise.

  <DT><CODE>def is_parsed(self):</CODE>
  <DD>True if the entity is parsed, false otherwise. (Not implemented
  by InternalEntity.)
  
  <DT><CODE>def get_pubid(self):</CODE>
  <DD>Returns the public identifier of the entity. (Not implemented
  by InternalEntity.)
  
  <DT><CODE>def get_sysid(self):</CODE>
  <DD>Returns the system identifier of the entity. (Not implemented
  by InternalEntity.) 
</DL>

<H2><A NAME="DTDConsumer">The DTDConsumer interface</A></H2>

<P>
This interface is used to receive parse events from the DTD parser.
</P>

<DL>
  <DT><CODE>def set_error_handler(self,err):</CODE>
  <DD>Sets the error handler of the DTDConsumer. The error handler
  does not have to be used, but the DTDConsumer must accept this
  method call.

  <DT><CODE>def dtd_start(self):</CODE>
  <DD>Called before any DTD events arrive. (Note: This will be called
  once for the internal DTD subset (if any) and once for the external
  DTD subset (if parsed).)

  <DT><CODE>def dtd_end(self):</CODE>
  <DD>Called when the DTD is completely parsed. (Note: This will be called
  once for the internal DTD subset (if any) and once for the external
  DTD subset (if parsed).)
  
  <DT><CODE>def new_comment(self,contents):</CODE>
  <DD>Called when a comment is encountered in the DTD.
  
  <DT><CODE>def new_pi(self,target,rem):</CODE>
  <DD>Called when a processing instruction is encountered in the DTD.
  
  <DT><CODE>def new_general_entity(self,name,val):</CODE>
  <DD>Called when an internal general entity declaration is
  encountered. 'val' contains the entity replacement text.
  
  <DT><CODE>def new_external_entity(self,ent_name,pub_id,sys_id,ndata):</CODE>
  <DD>Called when an external general entity declaration is
  encountered. 'ndata' is the name of the associated notation, or None
  if none was associated.
  
  <DT><CODE>def new_parameter_entity(self,name,val):</CODE>
  <DD>Called when an internal parameter entity declaration is
  encountered. 'val' contains the entity replacement text.
  
  <DT><CODE>def new_external_pe(self,name,pubid,sysid):</CODE>
  <DD>Called when an external parameter entity declaration is
  encountered.
  
  <DT><CODE>def new_notation(self,name,pubid,sysid):</CODE>
  <DD>Called when a notation declaration is encountered.
  
  <DT><CODE>def new_element_type(self,elem_name,elem_cont):</CODE>
  <DD>Called when an element type declaration is encountered.
  'elem_cont' is a ContentModel object. (Email me if you want more
  information about how to deal with content models.)
  
  <DT><CODE>def new_attribute(self,elem,attr,a_type,a_decl,a_def):</CODE>
  <DD>Called when an attribute declaration is encountered. 'elem' is
  the name of the element, 'attr' the name of the attribute, 'a_type'
  the name of the attribute type (ID, CDATA...), 'a_decl' the name of
  the declared default type (#REQUIRED, #IMPLIED...) and 'a_def' the
  declared default value (or None if none were declared).

  <DT><CODE>def handle_comment(self,contents):</CODE>
  <DD>Called when a comment is encountered inside the DTD.

  <DT><CODE>def handle_pi(self,target,data):</CODE>
  <DD>Called when a processing instruction is encountered inside the DTD.
</DL>


<HR>

<ADDRESS>
11.Sep.98 19:23, 
<A HREF="../../../lmg.html">Lars Marius Garshol</A>,
<A HREF="mailto:larsga@ifi.uio.no">larsga@ifi.uio.no</A>.
</ADDRESS>

</BODY>
</HTML>