1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6#include "nsISupports.idl"
7interface nsIScriptError;
8
9/**
10 * This interface should be implemented by any content sink that wants
11 * to get output from expat and do something with it; in other words,
12 * by any sink that handles some sort of XML dialect.
13 */
14
15[scriptable, uuid(01f681af-0f22-4725-a914-0d396114daf0)]
16interface nsIExpatSink : nsISupports
17{
18  /**
19   * Called to handle the opening tag of an element.
20   * @param aName the fully qualified tagname of the element
21   * @param aAtts the array of attribute names and values.  There are
22   *        aAttsCount/2 names and aAttsCount/2 values, so the total number of
23   *        elements in the array is aAttsCount.  The names and values
24   *        alternate.  Thus, if we number attributes starting with 0,
25   *        aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is
26   *        the value of that attribute  Both explicitly specified attributes
27   *        and attributes that are defined to have default values in a DTD are
28   *        present in aAtts.
29   * @param aAttsCount the number of elements in aAtts.
30   * @param aLineNumber the line number of the start tag in the data stream.
31   * @param aColumnNumber the column number of the start tag in the data stream.
32   */
33  void HandleStartElement(in wstring aName,
34                          [array, size_is(aAttsCount)] in wstring aAtts,
35                          in unsigned long aAttsCount,
36                          in unsigned long aLineNumber,
37                          in unsigned long aColumnNumber);
38
39  /**
40   * Called to handle the closing tag of an element.
41   * @param aName the fully qualified tagname of the element
42   */
43  void HandleEndElement(in wstring aName);
44
45  /**
46   * Called to handle a comment
47   * @param aCommentText the text of the comment (not including the
48   *        "<!--" and "-->")
49   */
50  void HandleComment(in wstring aCommentText);
51
52  /**
53   * Called to handle a CDATA section
54   * @param aData the text in the CDATA section.  This is null-terminated.
55   * @param aLength the length of the aData string
56   */
57  void HandleCDataSection([size_is(aLength)] in wstring aData,
58                          in unsigned long aLength);
59
60  /**
61   * Called to handle the doctype declaration
62   */
63  void HandleDoctypeDecl(in AString aSubset,
64                         in AString aName,
65                         in AString aSystemId,
66                         in AString aPublicId,
67                         in nsISupports aCatalogData);
68
69  /**
70   * Called to handle character data.  Note that this does NOT get
71   * called for the contents of CDATA sections.
72   * @param aData the data to handle.  aData is NOT NULL-TERMINATED.
73   * @param aLength the length of the aData string
74   */
75  void HandleCharacterData([size_is(aLength)] in wstring aData,
76                           in unsigned long aLength);
77
78  /**
79   * Called to handle a processing instruction
80   * @param aTarget the PI target (e.g. xml-stylesheet)
81   * @param aData all the rest of the data in the PI
82   */
83  void HandleProcessingInstruction(in wstring aTarget,
84                                   in wstring aData);
85
86  /**
87   * Handle the XML Declaration.
88   *
89   * @param aVersion    The version string, can be null if not specified.
90   * @param aEncoding   The encoding string, can be null if not specified.
91   * @param aStandalone -1, 0, or 1 indicating respectively that there was no
92   *                    standalone parameter in the declaration, that it was
93   *                    given as no, or that it was given as yes.
94   */
95  void HandleXMLDeclaration(in wstring aVersion,
96                            in wstring aEncoding,
97                            in long aStandalone);
98
99  /**
100   * Ask the content sink if the expat driver should log an error to the console.
101   *
102   * @param aErrorText  Error message to pass to content sink.
103   * @param aSourceText Source text of the document we're parsing.
104   * @param aError      Script error object with line number & column number
105   *
106   * @retval True if the expat driver should report the error.
107   */
108  boolean ReportError(in wstring aErrorText,
109                      in wstring aSourceText,
110                      in nsIScriptError aError);
111};
112