alexejk / go-xmlrpc

An XML-RPC Client for Go
https://alexejk.io/article/handling-xmlrpc-in-go/
MIT License
19 stars 7 forks source link

Need a script to transform xml request to RPC call struct #47

Closed yangyao closed 2 years ago

yangyao commented 2 years ago

And also transform xml response to go struct

After a lot of struggle, I found the following pattern. ( Notice the green text

image

yangyao commented 2 years ago

For this type of struct . not able to transform

<methodResponse>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>2</name>
                        <value>
                            <struct>
                                <member>
                                    <name>tag_id</name>
                                    <value>
                                        <string>2</string>
                                    </value>
                                </member>
                                <member>
                                    <name>name</name>
                                    <value>
                                        <string>product01-tag02</string>
                                    </value>
                                </member>
                            </struct>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodResponse>

&struct {
    2 : struct {
        TagId : string,
        Name : string 
    }
}

not able to define this kind of struct ..

use raw http response . and xmlpath to get data

/methodResponse/params/param/value/struct/member/value/struct/member[name="name"]/value/string/text()
alexejk commented 2 years ago

This should now be possible with v0.4.0 by using xmlrpc tag on fields. Specifically, you can remap the field with something like this:

&struct {
    Two: struct {
        TagId : string,
        Name : string 
    } `xmlrpc:"2"`
}