Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(132)

Delta Between Two Patch Sets: src/pkg/encoding/xml/decodectx_test.go

Issue 6868044: code review 6868044: encoding/xml: namespace handling
Left Patch Set: diff -r 0320ad78230f https://code.google.com/p/go Created 11 years, 3 months ago
Right Patch Set: diff -r 8ea98ec93704 https://code.google.com/p/go Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/encoding/xml/atom_test.go ('k') | src/pkg/encoding/xml/marshal.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package xml
6
7 // Tests specific to the context object which is included in Encoder
8 // and Decoder.
9
10 import (
11 "fmt"
12 "io"
13 "strings"
14 )
15
16 type XmppErr struct {
17 XMLName Name `xml:"xmpp1 error"`
18 Text XmppErrTxt `xml:",any"`
19 }
20
21 type XmppErrTxt struct {
22 XMLName Name
23 }
24
25 var decodectxstr = `<stream:error><blah xmlns="xmpp2"></blah></stream:error>`
26
27 // Imagine we need to read from the middle of an XML document, after
28 // namespaces and prefixes have already been declared. It's possible
29 // to load that context into the Decoder.
30 func ExampleDecoder_context() {
31 datardr := strings.NewReader(decodectxstr)
32 // Make a dummy start-tag with the document's namespace
33 // declarations.
34 nsstr := `<a xmlns="xmpp0" xmlns:stream="xmpp1">`
35 nsrdr := strings.NewReader(nsstr)
36 r := io.MultiReader(nsrdr, datardr)
37 dec := NewDecoder(r)
38 // Read and discard the start-tag; this has the side effect of
39 // loading namespace prefixes.
40 dec.Token()
41 val := &XmppErr{}
42 err := dec.Decode(val)
43 if err != nil {
44 fmt.Printf("Decode: %s", err)
45 return
46 }
47 fmt.Printf("%#v", val)
48 // Output:
49 // &xml.XmppErr{XMLName:xml.Name{Space:"xmpp1", Local:"error"}, Text:xml .XmppErrTxt{XMLName:xml.Name{Space:"xmpp2", Local:"blah"}}}
50 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b