@@ -503,6 +503,11 @@ type TableAttrs struct {
503
503
type TAttr struct {
504
504
HTable string `xml:"http://www.w3.org/TR/html4/ table,attr"`
505
505
FTable string `xml:"http://www.w3schools.com/furniture table,attr"`
506
+ Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
507
+ Other1 string `xml:"http://golang.org/xml/ other,attr,omitempty"`
508
+ Other2 string `xml:"http://golang.org/xmlfoo/ other,attr,omitempty"`
509
+ Other3 string `xml:"http://golang.org/json/ other,attr,omitempty"`
510
+ Other4 string `xml:"http://golang.org/2/json/ other,attr,omitempty"`
506
511
}
507
512
508
513
var tableAttrs = []struct {
@@ -514,33 +519,33 @@ var tableAttrs = []struct {
514
519
xml : `<TableAttrs xmlns:f="http://www.w3schools.com/furniture" xmlns:h="http://www.w3.org/TR/html4/"><TAttr ` +
515
520
`h:table="hello" f:table="world" ` +
516
521
`/></TableAttrs>` ,
517
- tab : TableAttrs {TAttr {"hello" , "world" }},
522
+ tab : TableAttrs {TAttr {HTable : "hello" , FTable : "world" }},
518
523
},
519
524
{
520
525
xml : `<TableAttrs><TAttr xmlns:f="http://www.w3schools.com/furniture" xmlns:h="http://www.w3.org/TR/html4/" ` +
521
526
`h:table="hello" f:table="world" ` +
522
527
`/></TableAttrs>` ,
523
- tab : TableAttrs {TAttr {"hello" , "world" }},
528
+ tab : TableAttrs {TAttr {HTable : "hello" , FTable : "world" }},
524
529
},
525
530
{
526
531
xml : `<TableAttrs><TAttr ` +
527
532
`h:table="hello" f:table="world" xmlns:f="http://www.w3schools.com/furniture" xmlns:h="http://www.w3.org/TR/html4/" ` +
528
533
`/></TableAttrs>` ,
529
- tab : TableAttrs {TAttr {"hello" , "world" }},
534
+ tab : TableAttrs {TAttr {HTable : "hello" , FTable : "world" }},
530
535
},
531
536
{
532
537
// Default space does not apply to attribute names.
533
538
xml : `<TableAttrs xmlns="http://www.w3schools.com/furniture" xmlns:h="http://www.w3.org/TR/html4/"><TAttr ` +
534
539
`h:table="hello" table="world" ` +
535
540
`/></TableAttrs>` ,
536
- tab : TableAttrs {TAttr {"hello" , "" }},
541
+ tab : TableAttrs {TAttr {HTable : "hello" , FTable : "" }},
537
542
},
538
543
{
539
544
// Default space does not apply to attribute names.
540
545
xml : `<TableAttrs xmlns:f="http://www.w3schools.com/furniture"><TAttr xmlns="http://www.w3.org/TR/html4/" ` +
541
546
`table="hello" f:table="world" ` +
542
547
`/></TableAttrs>` ,
543
- tab : TableAttrs {TAttr {"" , "world" }},
548
+ tab : TableAttrs {TAttr {HTable : "" , FTable : "world" }},
544
549
},
545
550
{
546
551
xml : `<TableAttrs><TAttr ` +
@@ -553,15 +558,15 @@ var tableAttrs = []struct {
553
558
xml : `<TableAttrs xmlns:h="http://www.w3.org/TR/html4/"><TAttr ` +
554
559
`h:table="hello" table="world" ` +
555
560
`/></TableAttrs>` ,
556
- tab : TableAttrs {TAttr {"hello" , "" }},
561
+ tab : TableAttrs {TAttr {HTable : "hello" , FTable : "" }},
557
562
ns : "http://www.w3schools.com/furniture" ,
558
563
},
559
564
{
560
565
// Default space does not apply to attribute names.
561
566
xml : `<TableAttrs xmlns:f="http://www.w3schools.com/furniture"><TAttr ` +
562
567
`table="hello" f:table="world" ` +
563
568
`/></TableAttrs>` ,
564
- tab : TableAttrs {TAttr {"" , "world" }},
569
+ tab : TableAttrs {TAttr {HTable : "" , FTable : "world" }},
565
570
ns : "http://www.w3.org/TR/html4/" ,
566
571
},
567
572
{
@@ -596,14 +601,23 @@ func TestUnmarshalNSAttr(t *testing.T) {
596
601
}
597
602
598
603
func TestMarshalNSAttr (t * testing.T ) {
599
- dst := TableAttrs {TAttr {"hello" , "world" }}
600
- data , err := Marshal (& dst )
604
+ src := TableAttrs {TAttr {"hello" , "world" , "en_US" , "other1" , "other2" , "other3" , "other4 " }}
605
+ data , err := Marshal (& src )
601
606
if err != nil {
602
607
t .Fatalf ("Marshal: %v" , err )
603
608
}
604
- want := `<TableAttrs><TAttr xmlns:_1 ="http://www.w3.org/TR/html4/" _1 :table="hello" xmlns:_2 ="http://www.w3schools.com/furniture" _2 :table="world"></TAttr></TableAttrs>`
609
+ want := `<TableAttrs><TAttr xmlns:html4 ="http://www.w3.org/TR/html4/" html4 :table="hello" xmlns:furniture ="http://www.w3schools.com/furniture" furniture :table="world" xml:lang="en_US" xmlns:_xml="http://golang.org/xml/" _xml:other="other1" xmlns:_xmlfoo="http://golang.org/xmlfoo/" _xmlfoo:other="other2" xmlns:json="http://golang.org/json/" json:other="other3" xmlns:json_1="http://golang.org/2/json/" json_1:other="other4 "></TAttr></TableAttrs>`
605
610
str := string (data )
606
611
if str != want {
607
- t .Errorf ("have: %q\n want: %q\n " , str , want )
612
+ t .Errorf ("Marshal:\n have: %#q\n want: %#q\n " , str , want )
613
+ }
614
+
615
+ var dst TableAttrs
616
+ if err := Unmarshal (data , & dst ); err != nil {
617
+ t .Errorf ("Unmarshal: %v" , err )
618
+ }
619
+
620
+ if dst != src {
621
+ t .Errorf ("Unmarshal = %q, want %q" , dst , src )
608
622
}
609
623
}
0 commit comments