-
Notifications
You must be signed in to change notification settings - Fork 35
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
Issue with the struct generated #20
Comments
Hello, I did not have any problem with the XML file you supplied, above.
Are you using the latest version of chidley? Here is 'mmm' (Go code generated from your XML by chidley):
Thanks, |
For the xml file: https://expirebox.com/download/abc77ad1602fa9c6c835dc1f15beac81.html The struct file that is created, if I save that as a go file <open_config_struct.go> where package is main, I get two errors, one the root being redeclared, which I fix by renaming the second root. ./open_config_struct.go:3151: Root redeclared in this block However, I get one more error: ./open_config_struct.go:757: undefined: xml in xml.Name This is for type ChiadminSt. I am clueless why this error is coming up. Thanks |
I tried your XML. It turns out this is 2 bugs. One easy to fix, one hard to fix (requires breaking changes to chidley): 1 - chidley creates a top level, called so chidley transforms this into
which collides with the chidley base struct, So to avoid such collisions, I have renamed the tag chidley uses for the root base, so this now produces for the base:
2 - The second bug is a little more complicated. If you compile the code generated by the above, you get this error:
Looking into your XML, it turns out you have two different event items (the 'Hyphen' is added by chidley as Go does not accept hyphens) in struct names, differing only with their capitalization: Line 14990:
and Line 53026:
chidley makes these into camel case, causing a name collision as the difference in the capitalization is lost in this transformation. For your issue, you can just go in and either change the XML or change the generated code. From the chidley perspective, this is a major bug: XML with tags that only differ in the capitalization of their tags' first letters will also be impacted this bug. My plan is to make a breaking change to chidley, with a new full version release. In the new version, no capitalization changes will be made to the names of the XML when transforming them to the struct names.
would become:
Note that the If have fixed the first bug in master, and will open an issue to make the breaking change. |
Hi @gnewton , I was able to fix the second issue as well, same way as you mentioned, renaming it. ./open_config_struct.go:757: undefined: xml in xml.Name This is for type ChiadminSt struct. |
@gnewton : nvm. The issue was something not to do with Chidley. Thanks! :) |
`package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
)
type Query struct {
rpc Rpc_reply
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc-reply,omitempty" json:"rpc-reply,omitempty"
}
type Addr_tag_list struct {
Addr_tag Addr_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 addr,omitempty" json:"addr,omitempty"
Pref_tag Pref_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 pref,omitempty" json:"pref,omitempty"
Tag Tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 tag,omitempty" json:"tag,omitempty"
Type_tag Type_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 type,omitempty" json:"type,omitempty"
VpcPeer_tag VpcPeer_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 vpcPeer,omitempty" json:"vpcPeer,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 Addr-list,omitempty" json:"Addr-list,omitempty"
}
type Dom_list struct {
If_items If_items
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 if-items,omitempty" json:"if-items,omitempty"
Name_tag Name_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 name,omitempty" json:"name,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 Dom-list,omitempty" json:"Dom-list,omitempty"
}
type If_list struct {
Addr_items_tag Addr_items_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 addr-items,omitempty" json:"addr-items,omitempty"
Id_tag Id_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 id,omitempty" json:"id,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 If-list,omitempty" json:"If-list,omitempty"
}
type Systemtag struct {
Ipv4_items Ipv4_items
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 ipv4-items,omitempty" json:"ipv4-items,omitempty"
Test_name Test_name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 test-name,omitempty" json:"test-name,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 System,omitempty" json:"System,omitempty"
}
type Addr_tag struct {
Text string
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 addr,omitempty" json:"addr,omitempty"
}
type Addr_items_tag struct {
Addr_tag_list Addr_tag_list
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 Addr-list,omitempty" json:"Addr-list,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 addr-items,omitempty" json:"addr-items,omitempty"
}
type Data_tag struct {
Systemtag Systemtag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 System,omitempty" json:"System,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 data,omitempty" json:"data,omitempty"
}
type Dom_items struct {
Dom_list []Dom_list
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 Dom-list,omitempty" json:"Dom-list,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 dom-items,omitempty" json:"dom-items,omitempty"
}
type Id_tag struct {
Text string
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 id,omitempty" json:"id,omitempty"
}
type If_items struct {
If_list []If_list
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 If-list,omitempty" json:"If-list,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 if-items,omitempty" json:"if-items,omitempty"
}
type Inst_items struct {
Dom_items Dom_items
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 dom-items,omitempty" json:"dom-items,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 inst-items,omitempty" json:"inst-items,omitempty"
}
type Ipv4_items struct {
Inst_items Inst_items
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 inst-items,omitempty" json:"inst-items,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 ipv4-items,omitempty" json:"ipv4-items,omitempty"
}
type Name_tag struct {
Text string
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 name,omitempty" json:"name,omitempty"
}
type Pref_tag struct {
Text bool
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 pref,omitempty" json:"pref,omitempty"
}
type Rpc_reply struct {
Attr_message_id string
xml:" message-id,attr" json:",omitempty"
Attr_xmlns string
xml:" xmlns,attr" json:",omitempty"
Data_tag Data_tag
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 data,omitempty" json:"data,omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc-reply,omitempty" json:"rpc-reply,omitempty"
}
type Tag struct {
Text bool
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 tag,omitempty" json:"tag,omitempty"
}
type Type_tag struct {
Text string
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 type,omitempty" json:"type,omitempty"
}
type VpcPeer_tag struct {
Text string
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 vpcPeer,omitempty" json:"vpcPeer,omitempty"
}
type Test_name struct {
Text string
xml:",chardata" json:",omitempty"
XMLName xml.Name
xml:"urn:ietf:params:xml:ns:netconf:base:1.0 test-name,omitempty" json:"test-name,omitempty"
}
func main() {
xmlFile, err := os.Open("interface.xml")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer xmlFile.Close()
}`
The structs above were generated using Chidley, I have removed the Chi prefix and the pointers.
When I try printing anything, its just a blank. Only #2 gives me the XML structure. Rest all blank.
Sample of my interface.xml file:
<?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"> <data> <System> <test-name>##WORK##</test-name> <ipv4-items> <inst-items> <dom-items> <Dom-list> <name>default</name> <if-items> <If-list> <id>eth5/8</id> <addr-items> <Addr-list> <addr>1.1.1.1</addr> <pref>1</pref> <tag>0</tag> <type>primary</type> <vpcPeer>0.0.0.0</vpcPeer> </Addr-list> </addr-items> </If-list> </if-items> </Dom-list> <Dom-list> <name>management</name> <if-items> <If-list> <id>eth5/8</id> <addr-items> <Addr-list> <addr>11.11.11.11</addr> <pref>1</pref> <tag>0</tag> <type>primary</type> <vpcPeer>0.0.0.0</vpcPeer> </Addr-list> </addr-items> </If-list> </if-items> </Dom-list> </dom-items> </inst-items> </ipv4-items> </System> </data> </rpc-reply>
The text was updated successfully, but these errors were encountered: