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: decoding a>b>c decoration syntax should support namespaces #37133

Open
wz2b opened this issue Feb 8, 2020 · 1 comment
Open

encoding/xml: decoding a>b>c decoration syntax should support namespaces #37133

wz2b opened this issue Feb 8, 2020 · 1 comment

Comments

@wz2b
Copy link

@wz2b wz2b commented Feb 8, 2020

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

$ go version
go version 1.13.5 windows/amd64

Does this issue reproduce with the latest release?

Yes, behaves same on 1.13.7

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

Windows/amd64 but this is repeatable at least on linux

go env Output
$ go env

What did you do?

I set up a struct with

I set up this set of structures

type myGetValueResponseEnvelope struct {
	XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
	Body    myGetValueResponseBody
}
type myGetValueResponseBody struct {
	XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
	Value   string   `xml:"getValueResponse>getValueReturn"`
}

to decode this XML:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <getValueResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <getValueReturn xsi:type="xsd:string">69.1</getValueReturn>
      </getValueResponse>
   </soapenv:Body>
</soapenv:Envelope>

but I wanted to eliminate the second object by using a>b>c syntax. Note though that the soapenv namespace is as far as Body but not farther. So I attempted this

type myGetValueResponseEnvelope struct {
	XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
	Value string `xml:"http//schemas.xmlsoap.org/soap/envelope Envelope>getValueResponse>getValueReturn"`
}

but it doesn't SEEM with a>b>c syntax that there's any way to have namespaces in all or (in my case) part of the xpath.

I can just eliminate the namespace requirement on Body and it actually decodes just fine, so this isn't an urgent issue at the moment, but some day I may want to be more selective. Regardless it seems the answer would be to split on > then ' ' then process it as usual.

@odeke-em odeke-em changed the title decoding xml a>b>c decoration syntax should support namespaces encoding/xml: decoding a>b>c decoration syntax should support namespaces Feb 8, 2020
@odeke-em

This comment has been minimized.

Copy link
Member

@odeke-em odeke-em commented Feb 8, 2020

Thank you for filing this issue @wz2b and welcome to the Go project!

I am not an XML expert but I shall kindly ping @mvdan @rogpeppe @nigeltao.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.