@@ -34,6 +34,12 @@ abstract class XMLLocatable extends @xmllocatable {
3434 * both of which can contain other elements.
3535 */
3636class XMLParent extends @xmlparent {
37+ XMLParent ( ) {
38+ // explicitly restrict `this` to be either an `XMLElement` or an `XMLFile`;
39+ // the type `@xmlparent` currently also includes non-XML files
40+ this instanceof @xmlelement or xmlEncoding ( this , _)
41+ }
42+
3743 /**
3844 * Gets a printable representation of this XML parent.
3945 * (Intended to be overridden in subclasses.)
@@ -121,7 +127,17 @@ class XMLFile extends XMLParent, File {
121127 XMLDTD getADTD ( ) { xmlDTDs ( result , _, _, _, this ) }
122128}
123129
124- /** A "Document Type Definition" of an XML file. */
130+ /**
131+ * An XML document type definition (DTD).
132+ *
133+ * Example:
134+ *
135+ * ```
136+ * <!ELEMENT person (firstName, lastName?)>
137+ * <!ELEMENT firstName (#PCDATA)>
138+ * <!ELEMENT lastName (#PCDATA)>
139+ * ```
140+ */
125141class XMLDTD extends @xmldtd {
126142 /** Gets the name of the root element of this DTD. */
127143 string getRoot ( ) { xmlDTDs ( this , result , _, _, _) }
@@ -148,7 +164,17 @@ class XMLDTD extends @xmldtd {
148164 }
149165}
150166
151- /** An XML tag in an XML file. */
167+ /**
168+ * An XML element in an XML file.
169+ *
170+ * Example:
171+ *
172+ * ```
173+ * <manifest xmlns:android="http://schemas.android.com/apk/res/android"
174+ * package="com.example.exampleapp" android:versionCode="1">
175+ * </manifest>
176+ * ```
177+ */
152178class XMLElement extends @xmlelement, XMLParent , XMLLocatable {
153179 /** Holds if this XML element has the given `name`. */
154180 predicate hasName ( string name ) { name = getName ( ) }
@@ -193,7 +219,16 @@ class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
193219 override string toString ( ) { result = XMLParent .super .toString ( ) }
194220}
195221
196- /** An attribute that occurs inside an XML element. */
222+ /**
223+ * An attribute that occurs inside an XML element.
224+ *
225+ * Examples:
226+ *
227+ * ```
228+ * package="com.example.exampleapp"
229+ * android:versionCode="1"
230+ * ```
231+ */
197232class XMLAttribute extends @xmlattribute, XMLLocatable {
198233 /** Gets the name of this attribute. */
199234 string getName ( ) { xmlAttrs ( this , _, result , _, _, _) }
@@ -214,7 +249,15 @@ class XMLAttribute extends @xmlattribute, XMLLocatable {
214249 override string toString ( ) { result = this .getName ( ) + "=" + this .getValue ( ) }
215250}
216251
217- /** A namespace used in an XML file */
252+ /**
253+ * A namespace used in an XML file.
254+ *
255+ * Example:
256+ *
257+ * ```
258+ * xmlns:android="http://schemas.android.com/apk/res/android"
259+ * ```
260+ */
218261class XMLNamespace extends @xmlnamespace {
219262 /** Gets the prefix of this namespace. */
220263 string getPrefix ( ) { xmlNs ( this , result , _, _) }
@@ -233,7 +276,15 @@ class XMLNamespace extends @xmlnamespace {
233276 }
234277}
235278
236- /** A comment of the form `<!-- ... -->` is an XML comment. */
279+ /**
280+ * A comment in an XML file.
281+ *
282+ * Example:
283+ *
284+ * ```
285+ * <!-- This is a comment. -->
286+ * ```
287+ */
237288class XMLComment extends @xmlcomment, XMLLocatable {
238289 /** Gets the text content of this XML comment. */
239290 string getText ( ) { xmlComments ( this , result , _, _) }
@@ -248,6 +299,12 @@ class XMLComment extends @xmlcomment, XMLLocatable {
248299/**
249300 * A sequence of characters that occurs between opening and
250301 * closing tags of an XML element, excluding other elements.
302+ *
303+ * Example:
304+ *
305+ * ```
306+ * <content>This is a sequence of characters.</content>
307+ * ```
251308 */
252309class XMLCharacters extends @xmlcharacters, XMLLocatable {
253310 /** Gets the content of this character sequence. */
0 commit comments