Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: decode error, such as <foo type="s" tp:type="string"> #19875

Closed
jouyouyun opened this issue Apr 7, 2017 · 1 comment
Closed

Comments

@jouyouyun
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.8

What operating system and processor architecture are you using (go env)?

linux 64

What did you do?

test code:

package main

import (
	"encoding/xml"
	"fmt"
	"strings"
)

var xmlData = `
<node>
	<interface name="org.freedesktop.NetworkManager.Device.Gre">
		<signal name="Changed">
			<arg name="changed" type="s"></arg>
		</signal>

		<signal name="PropertiesChanged">
		    <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
		        <tp:docstring>
		            A dictionary mapping property names to variant boxed values
		        </tp:docstring>
		    </arg>
		</signal>
	</interface>
</node>
`

type NodeInfo struct {
	Interface struct {
		Signals []SignalInfo `xml:"signal"`
	} `xml:"interface"`
}

type SignalInfo struct {
	Name string  `xml:"name,attr"`
	Arg  ArgInfo `xml:"arg"`
}

type ArgInfo struct {
	Name string `xml:"name,attr"`
	Type string `xml:"type,attr"`
}

func main() {
	reader := strings.NewReader(xmlData)
	decoder := xml.NewDecoder(reader)
	var info NodeInfo
	err := decoder.Decode(&info)
	if err != nil {
		fmt.Println("Failed to decode:", err)
		return
	}

	for _, signal := range info.Interface.Signals {
		fmt.Println("Signal:", signal.Name)
		fmt.Printf("\tName: %s\n\tType: %s\n", signal.Arg.Name, signal.Arg.Type)
	}
}

I expected the signal PropertiesChanged 's type to a{sv}, but the result was String_Variant_Map.

What did you expect to see?

I expected the signal PropertiesChanged 's type to a{sv}

What did you see instead?

but the result was String_Variant_Map

@SamWhited
Copy link
Member

Duplicate of section 4 on #14407 and, more specifically, of #8535; let's track this there. Thanks!

@golang golang locked and limited conversation to collaborators Apr 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants