exml 0.7.2

Pure Rust XML library based on libxml2
Documentation
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
use std::borrow::Cow;

use crate::{
    chvalid::XmlCharValid,
    error::XmlParserErrors,
    parser::{
        XML_MAX_HUGE_LENGTH, XML_MAX_TEXT_LENGTH, XML_SUBSTITUTE_REF, XmlParserCtxt,
        XmlParserInputState, XmlParserOption, check_language_id, xml_err_memory, xml_fatal_err,
        xml_fatal_err_msg, xml_fatal_err_msg_str, xml_warning_msg,
    },
    tree::{NodeCommon, XML_ENT_CHECKED, XmlEntityType},
};

/// Normalize the space in non CDATA attribute values:
/// If the attribute type is not CDATA, then the XML processor MUST further
/// process the normalized attribute value by discarding any leading and
/// trailing space (#x20) characters, and by replacing sequences of space
/// (#x20) characters by a single space (#x20) character.
/// Note that the size of dst need to be at least src, and if one doesn't need
/// to preserve dst (and it doesn't come from a dictionary or read-only) then
/// passing src as dst is just fine.
///
/// If some conversion occurs, return the original string wrapped `Cow::Borrowed`.  
/// Otherwise, return the modified string wrapped `Cow::Owned`.
#[doc(alias = "xmlAttrNormalizeSpace")]
pub(crate) fn attr_normalize_space(mut src: &str) -> Cow<'_, str> {
    src = src.trim_matches(' ');
    if !src.contains("  ") {
        return Cow::Borrowed(src);
    }
    let mut dst = String::with_capacity(src.len());
    let mut src = src.chars().peekable();
    while let Some(b) = src.next() {
        if b == ' ' {
            // reduce single spaces
            while src.next_if(|&b| b == ' ').is_some() {}
            if src.peek().is_some() {
                dst.push(' ');
            }
        } else {
            dst.push(b);
        }
    }
    Cow::Owned(dst)
}

impl XmlParserCtxt<'_> {
    /// Parse a value for an attribute.
    ///
    /// # Note
    /// If no normalization is needed, the routine will return pointers directly from the data buffer.
    ///
    /// 3.3.3 Attribute-Value Normalization:
    /// Before the value of an attribute is passed to the application or
    /// checked for validity, the XML processor must normalize it as follows:
    /// - a character reference is processed by appending the referenced
    ///   character to the attribute value
    /// - an entity reference is processed by recursively processing the
    ///   replacement text of the entity
    /// - a whitespace character (#x20, #xD, #xA, #x9) is processed by
    ///   appending #x20 to the normalized value, except that only a single
    ///   #x20 is appended for a "#xD#xA" sequence that is part of an external
    ///   parsed entity or the literal entity value of an internal parsed entity
    /// - other characters are processed by appending them to the normalized value
    ///   If the declared value is not CDATA, then the XML processor must further
    ///   process the normalized attribute value by discarding any leading and
    ///   trailing space (#x20) characters, and by replacing sequences of space
    ///   (#x20) characters by a single space (#x20) character.
    ///   All attributes for which no declaration has been read should be treated
    ///   by a non-validating parser as if declared CDATA.
    ///
    /// Returns the AttValue parsed or NULL. The value has to be freed by the
    ///     caller if it was copied, this can be detected by val[*len] == 0.
    #[doc(alias = "xmlParseAttValueInternal")]
    pub(crate) fn parse_att_value_internal(&mut self, normalize: bool) -> Option<String> {
        let max_length = if self.options & XmlParserOption::XmlParseHuge as i32 != 0 {
            XML_MAX_HUGE_LENGTH
        } else {
            XML_MAX_TEXT_LENGTH
        };

        macro_rules! GROW_PARSE_ATT_VALUE_INTERNAL {
            ($self:expr, $input:expr, $start:expr) => {
                let diff = $start.len() - $input.len();
                $self.grow();
                if matches!($self.instate, XmlParserInputState::XmlParserEOF) {
                    return None;
                }
                $start = $self.content_bytes();
                $input = &$start[diff..];
            };
        }

        self.grow();
        let input = self.content_bytes();
        let mut line: i32 = self.input().unwrap().line;
        let mut col: i32 = self.input().unwrap().col;
        if input.is_empty() || (input[0] != b'"' && input[0] != b'\'') {
            xml_fatal_err(self, XmlParserErrors::XmlErrAttributeNotStarted, None);
            return None;
        }
        self.instate = XmlParserInputState::XmlParserAttributeValue;
        let mut input = self.content_bytes();

        // try to handle in this routine the most common case where no
        // allocation of a new string is required and where content is pure ASCII.
        let limit = input[0];
        input = &input[1..];
        col += 1;
        let mut start = input;
        if input.is_empty() {
            GROW_PARSE_ATT_VALUE_INTERNAL!(self, input, start);
        }
        let (last, consumed) = if normalize {
            let mut trimmed = 0;
            // Skip any leading spaces
            while !input.is_empty()
                && input[0] != limit
                && matches!(input[0], b'\x20' | b'\t' | b'\n' | b'\r')
            {
                if input[0] == 0xA {
                    line += 1;
                    col = 1;
                } else {
                    col += 1;
                }
                input = &input[1..];
                trimmed += 1;
                start = input;
                if input.is_empty() {
                    GROW_PARSE_ATT_VALUE_INTERNAL!(self, input, start);
                    if start.len() - input.len() > max_length {
                        xml_fatal_err_msg(
                            self,
                            XmlParserErrors::XmlErrAttributeNotFinished,
                            "AttValue length too long\n",
                        );
                        return None;
                    }
                }
            }
            while !input.is_empty()
                && input[0] != limit
                && input[0] != b'&'
                && input[0] != b'<'
                && matches!(input[0], b'\x20'..=b'\x7F')
            {
                col += 1;
                let now = input[0];
                input = &input[1..];
                if now == b'\x20' && !input.is_empty() && input[0] == b'\x20' {
                    break;
                }
                if input.is_empty() {
                    GROW_PARSE_ATT_VALUE_INTERNAL!(self, input, start);
                    if start.len() - input.len() > max_length {
                        xml_fatal_err_msg(
                            self,
                            XmlParserErrors::XmlErrAttributeNotFinished,
                            "AttValue length too long\n",
                        );
                        return None;
                    }
                }
            }
            // skip the trailing blanks
            let mut len = start.len() - input.len();
            while len > 0 && start[len - 1] == b'\x20' {
                len -= 1;
            }
            let mut last = &start[len..];
            while !input.is_empty()
                && input[0] != limit
                && matches!(input[0], b'\x20' | b'\t' | b'\n' | b'r')
            {
                if input[0] == 0xA {
                    line += 1;
                    col = 1;
                } else {
                    col += 1;
                }
                input = &input[1..];
                if input.is_empty() {
                    let diff = start.len() - input.len();
                    let diffl = start.len() - last.len();
                    self.grow();
                    if matches!(self.instate, XmlParserInputState::XmlParserEOF) {
                        return None;
                    }
                    start = self.content_bytes();
                    input = &start[diff..];
                    last = &start[diffl..];

                    if start.len() - input.len() > max_length {
                        xml_fatal_err_msg(
                            self,
                            XmlParserErrors::XmlErrAttributeNotFinished,
                            "AttValue length too long\n",
                        );
                        return None;
                    }
                }
            }
            if start.len() - input.len() > max_length {
                xml_fatal_err_msg(
                    self,
                    XmlParserErrors::XmlErrAttributeNotFinished,
                    "AttValue length too long\n",
                );
                return None;
            }
            if input.is_empty() || input[0] != limit {
                return self.parse_att_value_complex(normalize);
            }
            (last, trimmed + start.len() - input.len())
        } else {
            while !input.is_empty()
                && input[0] != limit
                && input[0] != b'&'
                && input[0] != b'<'
                && matches!(input[0], b'\x20'..=b'\x7F')
            {
                input = &input[1..];
                col += 1;
                if input.is_empty() {
                    GROW_PARSE_ATT_VALUE_INTERNAL!(self, input, start);
                    if start.len() - input.len() > max_length {
                        xml_fatal_err_msg(
                            self,
                            XmlParserErrors::XmlErrAttributeNotFinished,
                            "AttValue length too long\n",
                        );
                        return None;
                    }
                }
            }
            if start.len() - input.len() > max_length {
                xml_fatal_err_msg(
                    self,
                    XmlParserErrors::XmlErrAttributeNotFinished,
                    "AttValue length too long\n",
                );
                return None;
            }
            if input.is_empty() || input[0] != limit {
                return self.parse_att_value_complex(normalize);
            }
            (input, start.len() - input.len())
        };
        col += 1;
        let len = start.len() - last.len();
        let ret = unsafe {
            // # Safety
            // If we can reach here, UTF-8 validation will never fail
            // because `start` contains only ASCII characters.
            String::from_utf8_unchecked(start[..len].to_vec())
        };
        // consumed : the length of parsed value (and trimmed spaces if `normalize` is `true`)
        // 1        : the head of `limit`
        // 1        : the tail of `limit`
        self.advance(consumed + 2);
        let input = self.input_mut().unwrap();
        input.line = line;
        input.col = col;
        Some(ret)
    }

    /// Parse a value for an attribute, this is the fallback function
    /// of xmlParseAttValue() when the attribute parsing requires handling
    /// of non-ASCII characters, or normalization compaction.
    ///
    /// Returns the AttValue parsed or NULL. The value has to be freed by the caller.
    #[doc(alias = "xmlParseAttValueComplex")]
    fn parse_att_value_complex(&mut self, normalize: bool) -> Option<String> {
        let max_length = if self.options & XmlParserOption::XmlParseHuge as i32 != 0 {
            XML_MAX_HUGE_LENGTH
        } else {
            XML_MAX_TEXT_LENGTH
        };
        let mut in_space: i32 = 0;

        let limit = if self.current_byte() == b'"' {
            self.instate = XmlParserInputState::XmlParserAttributeValue;
            self.skip_char();
            b'"'
        } else if self.current_byte() == b'\'' {
            self.instate = XmlParserInputState::XmlParserAttributeValue;
            self.skip_char();
            b'\''
        } else {
            xml_fatal_err(self, XmlParserErrors::XmlErrAttributeNotStarted, None);
            return None;
        };

        // allocate a translation buffer.
        let mut buf = String::with_capacity(100);
        // OK loop until we reach one of the ending c_char or a size limit.
        let mut c = self.current_char();
        while let Some(nc) = c.filter(|&c| {
            self.current_byte() != limit
                && c.is_xml_char()
                && c != '<'
                && !matches!(self.instate, XmlParserInputState::XmlParserEOF)
        }) {
            if nc == '&' {
                in_space = 0;
                if self.nth_byte(1) == b'#' {
                    let val = self.parse_char_ref();
                    if val == Some('&') {
                        if self.replace_entities {
                            buf.push('&');
                        } else {
                            // The reparsing will be done in xmlStringGetNodeList()
                            // called by the attribute() function in SAX.c
                            buf.push_str("&#38;");
                        }
                    } else if let Some(val) = val {
                        buf.push(val);
                    }
                } else {
                    let ent = self.parse_entity_ref();
                    if let Some(ent) = ent.filter(|ent| {
                        matches!(ent.etype, XmlEntityType::XmlInternalPredefinedEntity)
                    }) {
                        let content = ent.content.as_deref().unwrap();
                        if !self.replace_entities && content.starts_with('&') {
                            buf.push_str("&#38;");
                        } else {
                            buf.push_str(content);
                        }
                    } else if let Some(ent) = ent.filter(|_| self.replace_entities) {
                        if !matches!(ent.etype, XmlEntityType::XmlInternalPredefinedEntity) {
                            if self.parser_entity_check(ent.length as _) != 0 {
                                return None;
                            }

                            self.depth += 1;
                            let rep = ent.content.as_deref().and_then(|content| {
                                self.string_decode_entities_int(
                                    content,
                                    XML_SUBSTITUTE_REF as _,
                                    '\0',
                                    '\0',
                                    '\0',
                                    1,
                                )
                            });
                            self.depth -= 1;
                            if let Some(rep) = rep {
                                for c in rep.chars() {
                                    if c == '\r' || c == '\n' || c == '\t' {
                                        buf.push('\x20');
                                    } else {
                                        buf.push(c);
                                    }
                                }
                            }
                        } else if let Some(content) = ent.content.as_deref() {
                            buf.push_str(content);
                        }
                    } else if let Some(mut ent) = ent {
                        // We also check for recursion and amplification
                        // when entities are not substituted. They're
                        // often expanded later.
                        if !matches!(ent.etype, XmlEntityType::XmlInternalPredefinedEntity)
                            && ent.content.is_some()
                        {
                            if ent.flags & XML_ENT_CHECKED as i32 == 0 {
                                let old_copy: u64 = self.sizeentcopy;

                                self.sizeentcopy = ent.length as _;

                                self.depth += 1;
                                let rep = self.string_decode_entities_int(
                                    ent.content.as_deref().unwrap(),
                                    XML_SUBSTITUTE_REF as _,
                                    '\0',
                                    '\0',
                                    '\0',
                                    1,
                                );
                                self.depth -= 1;

                                // If we're parsing DTD content, the entity
                                // might reference other entities which
                                // weren't defined yet, so the check isn't
                                // reliable.
                                if self.in_subset == 0 {
                                    ent.flags |= XML_ENT_CHECKED as i32;
                                    ent.expanded_size = self.sizeentcopy;
                                }

                                if rep.is_none() {
                                    ent.content = Some(Cow::Borrowed(""));
                                }

                                if self.parser_entity_check(old_copy) != 0 {
                                    return None;
                                }
                            } else if self.parser_entity_check(ent.expanded_size) != 0 {
                                return None;
                            }
                        }

                        // Just output the reference
                        buf.push('&');
                        buf.push_str(&ent.name().unwrap());
                        buf.push(';');
                    }
                }
            } else {
                if nc == '\u{20}' || nc == '\u{D}' || nc == '\u{A}' || nc == '\u{9}' {
                    if !buf.is_empty() || !normalize {
                        if !normalize || in_space == 0 {
                            buf.push('\x20');
                        }
                        in_space = 1;
                    }
                } else {
                    in_space = 0;
                    buf.push(nc);
                }
                self.advance_with_line_handling(nc.len_utf8());
            }
            self.grow();
            c = self.current_char();
            if buf.len() > max_length {
                xml_fatal_err_msg(
                    self,
                    XmlParserErrors::XmlErrAttributeNotFinished,
                    "AttValue length too long\n",
                );
                xml_err_memory(Some(self), None);
                return None;
            }
        }
        if matches!(self.instate, XmlParserInputState::XmlParserEOF) {
            return None;
        }

        if in_space != 0 && normalize {
            while buf.ends_with('\x20') {
                buf.pop();
            }
        }
        if self.current_byte() == b'<' {
            xml_fatal_err(self, XmlParserErrors::XmlErrLtInAttribute, None);
        } else if self.current_byte() != limit {
            if c.is_some_and(|c| !c.is_xml_char()) {
                xml_fatal_err_msg(
                    self,
                    XmlParserErrors::XmlErrInvalidChar,
                    "invalid character in attribute value\n",
                );
            } else {
                xml_fatal_err_msg(
                    self,
                    XmlParserErrors::XmlErrAttributeNotFinished,
                    "AttValue: ' expected\n",
                );
            }
        } else {
            self.skip_char();
        }

        Some(buf)
    }

    /// parse a value for an attribute
    /// Note: the parser won't do substitution of entities here, this
    /// will be handled later in xmlStringGetNodeList
    ///
    /// ```text
    /// [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
    /// ```
    ///
    /// # 3.3.3 Attribute-Value Normalization:
    /// Before the value of an attribute is passed to the application or
    /// checked for validity, the XML processor must normalize it as follows:
    /// - a character reference is processed by appending the referenced
    ///   character to the attribute value
    /// - an entity reference is processed by recursively processing the
    ///   replacement text of the entity
    /// - a whitespace character (#x20, #xD, #xA, #x9) is processed by
    ///   appending #x20 to the normalized value, except that only a single
    ///   #x20 is appended for a "#xD#xA" sequence that is part of an external
    ///   parsed entity or the literal entity value of an internal parsed entity
    /// - other characters are processed by appending them to the normalized value
    ///   If the declared value is not CDATA, then the XML processor must further
    ///   process the normalized attribute value by discarding any leading and
    ///   trailing space (#x20) characters, and by replacing sequences of space
    ///   (#x20) characters by a single space (#x20) character.
    ///   All attributes for which no declaration has been read should be treated
    ///   by a non-validating parser as if declared CDATA.
    ///
    /// Returns the AttValue parsed or NULL. The value has to be freed by the caller.
    #[doc(alias = "xmlParseAttValue")]
    pub(crate) fn parse_att_value(&mut self) -> Option<String> {
        self.input()?;
        self.parse_att_value_internal(false)
    }

    /// Parse an attribute
    ///
    /// ```text
    /// [41] Attribute ::= Name Eq AttValue
    ///
    /// [ WFC: No External Entity References ]
    /// Attribute values cannot contain direct or indirect entity references
    /// to external entities.
    ///
    /// [ WFC: No < in Attribute Values ]
    /// The replacement text of any entity referred to directly or indirectly in
    /// an attribute value (other than "&lt;") must not contain a <.
    ///
    /// [ VC: Attribute Value Type ]
    /// The attribute must have been declared; the value must be of the type declared for it.
    ///
    /// [25] Eq ::= S? '=' S?
    ///
    /// With namespace:
    /// [NS 11] Attribute ::= QName Eq AttValue
    /// ```
    ///
    /// Also the case QName == xmlns:??? is handled independently as a namespace definition.
    ///
    /// Returns (Name, AttValue).
    #[doc(alias = "xmlParseAttribute")]
    #[cfg(feature = "sax1")]
    pub(crate) fn parse_attribute(&mut self) -> (Option<String>, Option<String>) {
        self.grow();
        let Some(name) = self.parse_name() else {
            xml_fatal_err_msg(
                self,
                XmlParserErrors::XmlErrNameRequired,
                "error parsing attribute name\n",
            );
            return (None, None);
        };

        // read the value
        self.skip_blanks();
        if self.current_byte() != b'=' {
            xml_fatal_err_msg_str!(
                self,
                XmlParserErrors::XmlErrAttributeWithoutValue,
                "Specification mandates value for attribute {}\n",
                name
            );
            return (Some(name), None);
        }

        self.skip_char();
        self.skip_blanks();
        let val = self.parse_att_value().unwrap();
        self.instate = XmlParserInputState::XmlParserContent;

        // Check that xml:lang conforms to the specification
        // No more registered as an error, just generate a warning now
        // since this was deprecated in XML second edition
        if self.pedantic && name == "xml:lang" && !check_language_id(&val) {
            xml_warning_msg!(
                self,
                XmlParserErrors::XmlWarLangValue,
                "Malformed value for xml:lang : {}\n",
                val
            );
        }

        // Check that xml:space conforms to the specification
        if name == "xml:space" {
            if val == "default" {
                *self.space_mut() = 0;
            } else if val == "preserve" {
                *self.space_mut() = 1;
            } else {
                xml_warning_msg!(
                    self,
                    XmlParserErrors::XmlWarSpaceValue,
                    "Invalid value \"{}\" for xml:space : \"default\" or \"preserve\" expected\n",
                    val
                );
            }
        }

        (Some(name), Some(val))
    }

    /// Returns (Prefix, LocalPart, AttValue).
    #[doc(alias = "xmlParseAttribute2")]
    pub(crate) fn parse_attribute2(
        &mut self,
        pref: Option<&str>,
        elem: &str,
    ) -> Option<(Option<String>, String, Option<String>)> {
        let mut normalize = false;

        self.grow();

        let (prefix, Some(name)) = self.parse_qname() else {
            xml_fatal_err_msg(
                self,
                XmlParserErrors::XmlErrNameRequired,
                "error parsing attribute name\n",
            );
            return None;
        };

        // get the type if needed
        if !self.atts_special.is_empty() {
            let fullname = pref.map_or(Cow::Borrowed(elem), |pref| {
                Cow::Owned(format!("{pref}:{elem}"))
            });
            let fullattr = prefix
                .as_deref()
                .map_or(Cow::Borrowed(name.as_str()), |pref| {
                    Cow::Owned(format!("{pref}:{name}"))
                });
            normalize = self.atts_special.contains_key(&(fullname, fullattr));
        }

        // read the value
        self.skip_blanks();

        if self.current_byte() != b'=' {
            xml_fatal_err_msg_str!(
                self,
                XmlParserErrors::XmlErrAttributeWithoutValue,
                "Specification mandates value for attribute {}\n",
                name
            );
            return Some((None, name, None));
        }
        self.skip_char();
        self.skip_blanks();
        let mut val = self.parse_att_value_internal(normalize)?;
        if normalize {
            // Sometimes a second normalisation pass for spaces is needed
            // but that only happens if charrefs or entities references
            // have been used in the attribute value, i.e. the attribute
            // value have been extracted in an allocated string already.
            let val2 = attr_normalize_space(&val);
            if val != val2 {
                val = val2.into_owned();
            }
        }
        self.instate = XmlParserInputState::XmlParserContent;

        if prefix.as_deref() == self.str_xml.as_deref() {
            // Check that xml:lang conforms to the specification
            // No more registered as an error, just generate a warning now
            // since this was deprecated in XML second edition
            if self.pedantic && name == "lang" && !check_language_id(&val) {
                xml_warning_msg!(
                    self,
                    XmlParserErrors::XmlWarLangValue,
                    "Malformed value for xml:lang : {}\n",
                    val
                );
            }

            // Check that xml:space conforms to the specification
            if name == "space" {
                if val == "default" {
                    *self.space_mut() = 0;
                } else if val == "preserve" {
                    *self.space_mut() = 1;
                } else {
                    xml_warning_msg!(
                        self,
                        XmlParserErrors::XmlWarSpaceValue,
                        "Invalid value \"{}\" for xml:space : \"default\" or \"preserve\" expected\n",
                        val
                    );
                }
            }
        }

        Some((prefix, name, Some(val)))
    }
}