@@ -71,17 +71,36 @@ impl std::error::Error for SyntaxError {}
7171/// [well-formed]: https://www.w3.org/TR/xml11/#dt-wellformed
7272#[ derive( Clone , Debug , PartialEq , Eq ) ]
7373pub enum IllFormedError {
74+ /// A `version` attribute was not found in an XML declaration or is not the
75+ /// first attribute.
76+ ///
77+ /// According to the [specification], the XML declaration (`<?xml ?>`) MUST contain
78+ /// a `version` attribute and it MUST be the first attribute. This error indicates,
79+ /// that the declaration does not contain attributes at all (if contains `None`)
80+ /// or either `version` attribute is not present or not the first attribute in
81+ /// the declaration. In the last case it contains the name of the found attribute.
82+ ///
83+ /// [specification]: https://www.w3.org/TR/xml11/#sec-prolog-dtd
84+ MissingDeclVersion ( Option < String > ) ,
85+ /// A document type definition (DTD) does not contain a name of a root element.
86+ ///
87+ /// According to the [specification], document type definition (`<!DOCTYPE foo>`)
88+ /// MUST contain a name which defines a document type (`foo`). If that name
89+ /// is missed, this error is returned.
90+ ///
91+ /// [specification]: https://www.w3.org/TR/xml11/#NT-doctypedecl
92+ MissingDoctypeName ,
7493 /// The end tag was not found during reading of a sub-tree of elements due to
7594 /// encountering an EOF from the underlying reader. This error is returned from
7695 /// [`Reader::read_to_end`].
7796 ///
7897 /// [`Reader::read_to_end`]: crate::reader::Reader::read_to_end
79- MissedEnd ( String ) ,
98+ MissingEndTag ( String ) ,
8099 /// The specified end tag was encountered without corresponding open tag at the
81100 /// same level of hierarchy
82- UnmatchedEnd ( String ) ,
101+ UnmatchedEndTag ( String ) ,
83102 /// The specified end tag does not match the start tag at that nesting level.
84- MismatchedEnd {
103+ MismatchedEndTag {
85104 /// Name of open tag, that is expected to be closed
86105 expected : String ,
87106 /// Name of actually closed tag
@@ -103,15 +122,25 @@ pub enum IllFormedError {
103122impl fmt:: Display for IllFormedError {
104123 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
105124 match self {
106- Self :: MissedEnd ( tag) => write ! (
125+ Self :: MissingDeclVersion ( None ) => {
126+ write ! ( f, "an XML declaration does not contain `version` attribute" )
127+ }
128+ Self :: MissingDeclVersion ( Some ( attr) ) => {
129+ write ! ( f, "an XML declaration must start with `version` attribute, but in starts with `{}`" , attr)
130+ }
131+ Self :: MissingDoctypeName => write ! (
132+ f,
133+ "`<!DOCTYPE>` declaration does not contain a name of a document type"
134+ ) ,
135+ Self :: MissingEndTag ( tag) => write ! (
107136 f,
108137 "start tag not closed: `</{}>` not found before end of input" ,
109138 tag,
110139 ) ,
111- Self :: UnmatchedEnd ( tag) => {
140+ Self :: UnmatchedEndTag ( tag) => {
112141 write ! ( f, "close tag `</{}>` does not match any open tag" , tag)
113142 }
114- Self :: MismatchedEnd { expected, found } => write ! (
143+ Self :: MismatchedEndTag { expected, found } => write ! (
115144 f,
116145 "expected `</{}>`, but `</{}>` was found" ,
117146 expected, found,
@@ -143,25 +172,6 @@ pub enum Error {
143172 ///
144173 /// [`encoding`]: index.html#encoding
145174 NonDecodable ( Option < Utf8Error > ) ,
146- /// A `version` attribute was not found in an XML declaration or is not the
147- /// first attribute.
148- ///
149- /// According to the [specification], the XML declaration (`<?xml ?>`) MUST contain
150- /// a `version` attribute and it MUST be the first attribute. This error indicates,
151- /// that the declaration does not contain attributes at all (if contains `None`)
152- /// or either `version` attribute is not present or not the first attribute in
153- /// the declaration. In the last case it contains the name of the found attribute.
154- ///
155- /// [specification]: https://www.w3.org/TR/xml11/#sec-prolog-dtd
156- XmlDeclWithoutVersion ( Option < String > ) ,
157- /// A document type definition (DTD) does not contain a name of a root element.
158- ///
159- /// According to the [specification], document type definition (`<!doctype foo>`)
160- /// MUST contain a name which defines a document type. If that name is missed,
161- /// this error is returned.
162- ///
163- /// [specification]: https://www.w3.org/TR/xml11/#NT-doctypedecl
164- EmptyDocType ,
165175 /// Attribute parsing error
166176 InvalidAttr ( AttrError ) ,
167177 /// Escape error
@@ -189,7 +199,7 @@ pub enum Error {
189199impl Error {
190200 pub ( crate ) fn missed_end ( name : QName , decoder : Decoder ) -> Self {
191201 match decoder. decode ( name. as_ref ( ) ) {
192- Ok ( name) => IllFormedError :: MissedEnd ( name. into ( ) ) . into ( ) ,
202+ Ok ( name) => IllFormedError :: MissingEndTag ( name. into ( ) ) . into ( ) ,
193203 Err ( err) => err. into ( ) ,
194204 }
195205 }
@@ -261,16 +271,6 @@ impl fmt::Display for Error {
261271 Error :: IllFormed ( e) => write ! ( f, "ill-formed document: {}" , e) ,
262272 Error :: NonDecodable ( None ) => write ! ( f, "Malformed input, decoding impossible" ) ,
263273 Error :: NonDecodable ( Some ( e) ) => write ! ( f, "Malformed UTF-8 input: {}" , e) ,
264- Error :: XmlDeclWithoutVersion ( None ) => {
265- write ! ( f, "an XML declaration does not contain `version` attribute" )
266- }
267- Error :: XmlDeclWithoutVersion ( Some ( attr) ) => {
268- write ! ( f, "an XML declaration must start with `version` attribute, but in starts with `{}`" , attr)
269- }
270- Error :: EmptyDocType => write ! (
271- f,
272- "`<!DOCTYPE>` declaration does not contain a name of a document type"
273- ) ,
274274 Error :: InvalidAttr ( e) => write ! ( f, "error while parsing attribute: {}" , e) ,
275275 Error :: EscapeError ( e) => write ! ( f, "{}" , e) ,
276276 Error :: UnknownPrefix ( prefix) => {
0 commit comments