writeAttrsTo writes the attributes of the start element to the provided writer.
(w TokenWriter)
| 45 | |
| 46 | // writeAttrsTo writes the attributes of the start element to the provided writer. |
| 47 | func (e *StartElement) writeAttrsTo(w TokenWriter) error { |
| 48 | for attr := range e.Attrs.Iter() { |
| 49 | if err := w.WriteByte(' '); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | quote := byte('"') |
| 54 | if strings.IndexByte(attr.Value, quote) != -1 { |
| 55 | quote = '\'' |
| 56 | } |
| 57 | |
| 58 | if _, err := w.WriteString(attr.Name.String()); err != nil { |
| 59 | return err |
| 60 | } |
| 61 | if err := w.WriteByte('='); err != nil { |
| 62 | return err |
| 63 | } |
| 64 | if err := w.WriteByte(quote); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | if _, err := w.WriteString(attr.Value); err != nil { |
| 68 | return err |
| 69 | } |
| 70 | if err := w.WriteByte(quote); err != nil { |
| 71 | return err |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | // EndElement represents an end element token (e.g., </tag>). |
| 79 | type EndElement struct { |