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

Fix default to cdataStringName for the type information of the tag specified by the -t flag #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ak1ra24
Copy link

@ak1ra24 ak1ra24 commented Dec 16, 2022

When converting from xml like the following, the string type is string string.
So I fixed it to use cdataStringName = Text.

Output before and after modification

Before

test.xml

<?xml version="1.0"?>
<todo_list type="list" identifier="1">
  <list type="struct">
    <ToDo>
      <id type="i8">1</id>
      <name type="string">a</name>
    </ToDo>
    <ToDo>
      <id type="i8">2</id>
      <name type="string">b</name>
    </ToDo>
  </list>
</todo_list>
chidley -t -F -e "" test.xml
type ToDo struct {
	XMLName xml.Name `xml:"ToDo,omitempty" json:"ToDo,omitempty"`
	Id *Id `xml:"id,omitempty" json:"id,omitempty"`
	Name *Name `xml:"name,omitempty" json:"name,omitempty"`
}

type Id struct {
	XMLName xml.Name `xml:"id,omitempty" json:"id,omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	Number int8 `xml:",chardata" json:",omitempty"`
}

type List struct {
	XMLName xml.Name `xml:"list,omitempty" json:"list,omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	ToDo []*ToDo `xml:"ToDo,omitempty" json:"ToDo,omitempty"`
}

type Name struct {
	XMLName xml.Name `xml:"name,omitempty" json:"name,omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	string string `xml:",chardata" json:",omitempty"`      <---- This is what I want to fix 
}

type Todo_list struct {
	XMLName xml.Name `xml:"todo_list,omitempty" json:"todo_list,omitempty"`
	Attridentifier string`xml:"identifier,attr"  json:",omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	List *List `xml:"list,omitempty" json:"list,omitempty"`
}

After

chidley -t -F -e "" test.xml
type ToDo struct {
	XMLName xml.Name `xml:"ToDo,omitempty" json:"ToDo,omitempty"`
	Id *Id `xml:"id,omitempty" json:"id,omitempty"`
	Name *Name `xml:"name,omitempty" json:"name,omitempty"`
}

type Id struct {
	XMLName xml.Name `xml:"id,omitempty" json:"id,omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	Number int8 `xml:",chardata" json:",omitempty"`
}

type List struct {
	XMLName xml.Name `xml:"list,omitempty" json:"list,omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	ToDo []*ToDo `xml:"ToDo,omitempty" json:"ToDo,omitempty"`
}

type Name struct {
	XMLName xml.Name `xml:"name,omitempty" json:"name,omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	Text string `xml:",chardata" json:",omitempty"`
}

type Todo_list struct {
	XMLName xml.Name `xml:"todo_list,omitempty" json:"todo_list,omitempty"`
	Attridentifier string`xml:"identifier,attr"  json:",omitempty"`
	Attrtype string`xml:"type,attr"  json:",omitempty"`
	List *List `xml:"list,omitempty" json:"list,omitempty"`
}

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

Successfully merging this pull request may close these issues.

1 participant