LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "reflect" | 10 "reflect" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 241 } |
242 if finfo.xmlns != "" && finfo.xmlns != start.Name.Space
{ | 242 if finfo.xmlns != "" && finfo.xmlns != start.Name.Space
{ |
243 e := "expected element <" + finfo.name + "> in n
ame space " + finfo.xmlns + " but have " | 243 e := "expected element <" + finfo.name + "> in n
ame space " + finfo.xmlns + " but have " |
244 if start.Name.Space == "" { | 244 if start.Name.Space == "" { |
245 e += "no name space" | 245 e += "no name space" |
246 } else { | 246 } else { |
247 e += start.Name.Space | 247 e += start.Name.Space |
248 } | 248 } |
249 return UnmarshalError(e) | 249 return UnmarshalError(e) |
250 } | 250 } |
251 » » » fv := finfo.Value(sv) | 251 » » » fv := finfo.value(sv) |
252 if _, ok := fv.Interface().(Name); ok { | 252 if _, ok := fv.Interface().(Name); ok { |
253 fv.Set(reflect.ValueOf(start.Name)) | 253 fv.Set(reflect.ValueOf(start.Name)) |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 // Assign attributes. | 257 // Assign attributes. |
258 // Also, determine whether we need to save character data or com
ments. | 258 // Also, determine whether we need to save character data or com
ments. |
259 for i := range tinfo.fields { | 259 for i := range tinfo.fields { |
260 finfo := &tinfo.fields[i] | 260 finfo := &tinfo.fields[i] |
261 switch finfo.flags & fMode { | 261 switch finfo.flags & fMode { |
262 case fAttr: | 262 case fAttr: |
263 » » » » strv := finfo.Value(sv) | 263 » » » » strv := finfo.value(sv) |
264 // Look for attribute. | 264 // Look for attribute. |
265 for _, a := range start.Attr { | 265 for _, a := range start.Attr { |
266 if a.Name.Local == finfo.name { | 266 if a.Name.Local == finfo.name { |
267 copyValue(strv, []byte(a.Value)) | 267 copyValue(strv, []byte(a.Value)) |
268 break | 268 break |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 case fCharData: | 272 case fCharData: |
273 if !saveData.IsValid() { | 273 if !saveData.IsValid() { |
274 » » » » » saveData = finfo.Value(sv) | 274 » » » » » saveData = finfo.value(sv) |
275 } | 275 } |
276 | 276 |
277 case fComment: | 277 case fComment: |
278 if !saveComment.IsValid() { | 278 if !saveComment.IsValid() { |
279 » » » » » saveComment = finfo.Value(sv) | 279 » » » » » saveComment = finfo.value(sv) |
280 } | 280 } |
281 | 281 |
282 case fAny: | 282 case fAny: |
283 if !saveAny.IsValid() { | 283 if !saveAny.IsValid() { |
284 » » » » » saveAny = finfo.Value(sv) | 284 » » » » » saveAny = finfo.value(sv) |
285 } | 285 } |
286 | 286 |
287 case fInnerXml: | 287 case fInnerXml: |
288 if !saveXML.IsValid() { | 288 if !saveXML.IsValid() { |
289 » » » » » saveXML = finfo.Value(sv) | 289 » » » » » saveXML = finfo.value(sv) |
290 if p.saved == nil { | 290 if p.saved == nil { |
291 saveXMLIndex = 0 | 291 saveXMLIndex = 0 |
292 p.saved = new(bytes.Buffer) | 292 p.saved = new(bytes.Buffer) |
293 } else { | 293 } else { |
294 saveXMLIndex = p.savedOffset() | 294 saveXMLIndex = p.savedOffset() |
295 } | 295 } |
296 } | 296 } |
297 } | 297 } |
298 } | 298 } |
299 } | 299 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if finfo.flags&fElement == 0 || len(finfo.parents) < len(parents
) { | 454 if finfo.flags&fElement == 0 || len(finfo.parents) < len(parents
) { |
455 continue | 455 continue |
456 } | 456 } |
457 for j := range parents { | 457 for j := range parents { |
458 if parents[j] != finfo.parents[j] { | 458 if parents[j] != finfo.parents[j] { |
459 continue Loop | 459 continue Loop |
460 } | 460 } |
461 } | 461 } |
462 if len(finfo.parents) == len(parents) && finfo.name == start.Nam
e.Local { | 462 if len(finfo.parents) == len(parents) && finfo.name == start.Nam
e.Local { |
463 // It's a perfect match, unmarshal the field. | 463 // It's a perfect match, unmarshal the field. |
464 » » » return true, p.unmarshal(finfo.Value(sv), start) | 464 » » » return true, p.unmarshal(finfo.value(sv), start) |
465 } | 465 } |
466 if len(finfo.parents) > len(parents) && finfo.parents[len(parent
s)] == start.Name.Local { | 466 if len(finfo.parents) > len(parents) && finfo.parents[len(parent
s)] == start.Name.Local { |
467 // It's a prefix for the field. Break and recurse | 467 // It's a prefix for the field. Break and recurse |
468 // since it's not ok for one field path to be itself | 468 // since it's not ok for one field path to be itself |
469 // the prefix for another field path. | 469 // the prefix for another field path. |
470 recurse = true | 470 recurse = true |
471 | 471 |
472 // We can reuse the same slice as long as we | 472 // We can reuse the same slice as long as we |
473 // don't try to append to it. | 473 // don't try to append to it. |
474 parents = finfo.parents[:len(parents)+1] | 474 parents = finfo.parents[:len(parents)+1] |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 case StartElement: | 522 case StartElement: |
523 if err := d.Skip(); err != nil { | 523 if err := d.Skip(); err != nil { |
524 return err | 524 return err |
525 } | 525 } |
526 case EndElement: | 526 case EndElement: |
527 return nil | 527 return nil |
528 } | 528 } |
529 } | 529 } |
530 panic("unreachable") | 530 panic("unreachable") |
531 } | 531 } |
LEFT | RIGHT |