trim updates the XML context to match the longest common prefix of the stack and the given parents. A closing tag will be written for every parent popped. Passing a zero slice or nil will close all the elements.
(parents []string)
| 1074 | // and the given parents. A closing tag will be written for every parent |
| 1075 | // popped. Passing a zero slice or nil will close all the elements. |
| 1076 | func (s *parentStack) trim(parents []string) error { |
| 1077 | split := 0 |
| 1078 | for ; split < len(parents) && split < len(s.stack); split++ { |
| 1079 | if parents[split] != s.stack[split] { |
| 1080 | break |
| 1081 | } |
| 1082 | } |
| 1083 | for i := len(s.stack) - 1; i >= split; i-- { |
| 1084 | if err := s.p.writeEnd(Name{Local: s.stack[i]}); err != nil { |
| 1085 | return err |
| 1086 | } |
| 1087 | } |
| 1088 | s.stack = s.stack[:split] |
| 1089 | return nil |
| 1090 | } |
| 1091 | |
| 1092 | // push adds parent elements to the stack and writes open tags. |
| 1093 | func (s *parentStack) push(parents []string) error { |