LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package xml | 5 package xml |
| 6 |
| 7 const ( |
| 8 XML_NS = "http://www.w3.org/XML/1998/namespace" |
| 9 XMLNS_NS = "http://www.w3.org/2000/xmlns/" |
| 10 ) |
6 | 11 |
7 // Track namespace context. This includes the namespace of the current | 12 // Track namespace context. This includes the namespace of the current |
8 // element, and also the mapping between namespace prefixes and | 13 // element, and also the mapping between namespace prefixes and |
9 // namespace URIs. The marshaler needs ns -> pfx, and the unmarshaler | 14 // namespace URIs. The marshaler needs ns -> pfx, and the unmarshaler |
10 // needs the opposite. Each element's associated context inherits from | 15 // needs the opposite. Each element's associated context inherits from |
11 // its parent's context. | 16 // its parent's context. |
12 type context struct { | 17 type context struct { |
13 // xmlns is the namespace (URI) of the current element. | 18 // xmlns is the namespace (URI) of the current element. |
14 xmlns string | 19 xmlns string |
15 // pfxmap is the mapping between prefix and namespace of the | 20 // pfxmap is the mapping between prefix and namespace of the |
(...skipping 26 matching lines...) Expand all Loading... |
42 child := &context{} | 47 child := &context{} |
43 child.pfxmap = make(map[string]string) | 48 child.pfxmap = make(map[string]string) |
44 child.parent = n | 49 child.parent = n |
45 return child | 50 return child |
46 } | 51 } |
47 | 52 |
48 func rootNs2Pfx() *context { | 53 func rootNs2Pfx() *context { |
49 n := &context{} | 54 n := &context{} |
50 n.pfxmap = make(map[string]string) | 55 n.pfxmap = make(map[string]string) |
51 n.parent = n | 56 n.parent = n |
52 » n.pfxmap["http://www.w3.org/XML/1998/namespace"] = "xml" | 57 » n.pfxmap[XML_NS] = "xml" |
53 » n.pfxmap["http://www.w3.org/2000/xmlns/"] = "xmlns" | 58 » n.pfxmap[XMLNS_NS] = "xmlns" |
54 return n | 59 return n |
55 } | 60 } |
56 | |
57 func rootPfx2Ns() *context { | |
58 n := &context{} | |
59 n.pfxmap = make(map[string]string) | |
60 n.parent = n | |
61 n.pfxmap["xml"] = "http://www.w3.org/XML/1998/namespace" | |
62 n.pfxmap["xmlns"] = "http://www.w3.org/2000/xmlns/" | |
63 return n | |
64 } | |
LEFT | RIGHT |