Giter Club home page Giter Club logo

chidley's People

Contributors

abh avatar bryant1410 avatar gnewton avatar xercoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chidley's Issues

Duplicate Struct Generated if mixed case used in XML

Great tool, thanks for developing!

I have an XML file that includes a couple of mixed case xml tags, which causes tool to generate duplicate structs. Here is the example:

https://www.dropbox.com/s/0jqqyvvk1ll6nm9/gamedata.xml?dl=0

	  <cluster ContinentType="Outlands" ClusterQuality="High">
		  <RareState state="0" weight="1556" />
		  <RareState state="1" weight="400" />
		  <RareState state="2" weight="40" />
		  <RareState state="3" weight="4" />
	  </cluster>

and then later:

         <Cluster default="0.05" minimum="0" maximum="0.05"/>

This causes duplicate structs to be generated in the xml. I know this xml probably isnt the best use case for chudley, but would be nice if it combined the 2 elements and generated code that still compiled.

Not able to generate execitable

Hi Team,

Can you please guide me how to generate an executable for this.
When I am running go build chidley.go I am getting following errors.

command-line-arguments

./chidley.go:50: undefined: PrintGoStructVisitor
./chidley.go:234: undefined: Node
./chidley.go:234: undefined: FQN
./chidley.go:268: undefined: FQN
./chidley.go:315: undefined: Source
./chidley.go:378: undefined: XMLType
./chidley.go:378: undefined: Node
./chidley.go:398: undefined: Node
./chidley.go:406: undefined: PrintGoStructVisitor
./chidley.go:406: too many errors

Generated code does not output values

The code that is generated with the -W flag does not include the values in the output JSON or XML. I tried this with my XML initially, but then with the examples that you provide. Here is a run of "test1" (minus the -f flag):

booty@limnognathia:gospace/src/github.com/gnewton/chidley$ ls
chidley              data              examples          fqn.go            jaxbTemplate.go  mvnTemplate.go   printGoStructVisitor.go  source.go        test_xml.sh   xml
chidley.go           decl.go           extractor.go      genericReader.go  LICENSE          node.go          printJavaJaxbVisitor.go  stdoutWriter.go  util.go       xml_source_test.go
codegenTemplates.go  encoding_test.go  fieldTemplate.go  javaTypes.go      makereadme       nodeTypeInfo.go  README.md                tests_util.go    util_test.go  xml_test.go

booty@limnognathia:gospace/src/github.com/gnewton/chidley$ ./chidley -W xml/test1.xml > examples/test1/ChidTest1.go

booty@limnognathia:gospace/src/github.com/gnewton/chidley$ cd examples/test1/

booty@limnognathia:gospace/src/github.com/gnewton/chidley/examples/test1$ go build

booty@limnognathia:gospace/src/github.com/gnewton/chidley/examples/test1$ ls
ChidTest1.go  test1

booty@limnognathia:gospace/src/github.com/gnewton/chidley/examples/test1$ ./test1 -x
  <docs language="eng">
      <doc type="book">
          <author>
              <firstName></firstName>
              <last-name></last-name>
          </author>
          <title></title>
      </doc>
      <doc type="article">
          <author>
              <firstName></firstName>
              <last-name></last-name>
          </author>
          <title></title>
      </doc>
  </docs>        

booty@limnognathia:gospace/src/github.com/gnewton/chidley/examples/test1$ cat ../../xml/test1.xml 
<?xml version="1.0"?>
<docs language="eng">
  <doc type="book">
    <title>Dune</title>
    <author>
      <last-name>Herbert</last-name>
      <firstName>Frank</firstName>
    </author>
  </doc>
  <doc type="article">
    <title>Brave New Wold</title>
    <author>
      <last-name>Huxley</last-name>
      <firstName>Aldous</firstName>
    </author>
  </doc>
</docs>
booty@limnognathia:gospace/src/github.com/gnewton/chidley/examples/test1$

The JSON output is similar in that the structure is all there, for the right number of elements, but the values themselves are missing.

Not handling XML namespaces correctly, creating incorrect Go identifiers for variable names

When xml like this is encountered:
<credit-words default-x="1124" default-y="1393" font-size="12" font-weight="bold" halign="right" justify="center" valign="top" xml:space="preserve">Words and Music by J.Bach</credit-words>

The "xml:" in xml:space refers to a name space which is: http://www.w3.org/XML/1998/namespace

However, chidley does not handle this properly, creating in a referencing struct:

AttrHttp://www.w3.org/XML/1998/namespaceSpace string `xml:"http://www.w3.org/XML/1998/namespace space,attr"`

Which does not compile due to the ': / .' characters in the variable name.

Instead, it should replace these characters in some canonical (if perhaps ugly) way, such as:
AttrHttp_colon__slash__slash_www_dot_w3_dot_org_slash_XML_slash_1998_slash_namespaceSpace xml:"http://www.w3.org/XML/1998/namespace space,attr"

Ugly like this to avoid accidental name clashes.

Double use of field name Text

In case an XML element has CharData as well as (possibly multiple) sub-elements with the name Text the resulting Go struct will have two fields called Text, e.g.

type Foo struct {
	Text []*Text `xml:"text,omitempty" json:"text,omitempty"`
	Text string `xml:",chardata" json:",omitempty"`
}

Issue with the struct generated

`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()

b, _ := ioutil.ReadAll(xmlFile)

var q Query
err2 := xml.Unmarshal(b, &q)
if err2 != nil {
	fmt.Printf("error: %v", err2)
	return
}
fmt.Println(q)
//#2fmt.Printf("%#v",q)
 fmt.Printf("%s",q.rpc.Attr_message_id);

}`

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>

Working on Selenium IDE Xml source

Hi @gnewton,

I found that chidley generated source is having problem dealing with the Selenium IDE Xml source (e.g. this one):

chidley -W ~/l/t/Wordpress.html > /tmp/Wordpress.go 

$ go run /tmp/Wordpress.go
Usage of /tmp/go-build915403080/command-line-arguments/_obj/exe/Wordpress:
  -c    Count each instance of XML tags
  -f string
        XML file or URL to read in (default "/path/to/l/t/Wordpress.html")
  -h    Usage
  -j    Convert to JSON
  -s    Stream XML by using XML elements one down from the root tag. Good for huge XML files (see http://blog.davidsingleton.org/parsing-huge-xml-files-with-go/
  -x    Convert to XML

$ go run /tmp/Wordpress.go -j ~/l/t/Wordpress.html 
{
 "html": {
  "Space": "",
  "Local": ""
 }
}

Is it supposed to output this few?

It's a normal xml file of:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
... 

Furthermore the -x Convert to XML can't handle such files:

$ go run /tmp/Wordpress.go -x ~/l/t/Wordpress.html 
error: main.ChiHtml field "AttrHttp_colon__slash__slash_www_dot_w3_dot_org_slash_XML_slash_1998_slash_namespaceLang" with tag "http://www.w3.org/XML/1998/namespace lang,attr" conflicts with field "AttrLang" with tag "lang,attr"

Would you look into it please?

Create multiple structs instead of merging same-name elements?

Right now Chidley merges all the child elements / attributes of each tag into a struct of the same name. Is there a way to tell it to keep separate XML elements instead of appending all the keys into a single master struct named the shared element name?

	<root>
		<children>
			<sub>
				<children>
					<foo>...</foo>
				</children>
			</sub>
		</children>
	</root>

Creates a struct that looks like this:

	type Children struct {
		Sub ...
		Foo ...
	}

Instead of multiple structs

type Children struct {
	Sub
}

type SubChildren struct {
	Foo
}

Read in multiple XML files of same type

Right now, only one XML file is used to build the XML 'model', so if it is missing some XML elements the model will be incomplete. However, if multiple XML files can be read and the union of them used to create the model, then elements that are in one but not in the other will be captured, and the model will be complete (actually, just more complete, i.e. as complete as all the XML files can make it)

JSON support

Hi @gnewton, would parsing JSON more difficult than parsing XML? Is you internal structure for parsed XML make it easy to accept JSON as the source as well?

The reason I'm asking is that, of all JSON to Go Struct packages that I found, all of them has limitations [1] that made them impractical to be used, which after years haven't been fixed.

Thus I'm hoping you will extend chidley to support JSON someday. Thx.

[1] github.com/ChimeraCoder/gojson/issues/14

Tests

Adding some tests would be a good thing.

Flag to allow collapse of structs that are only a single string with no attrubutes

Given the following XML:

<cars>
  <car>
    <type>Ford</type>
    <struct>small</struct>
  </car>
  <car>
    <type>Honda</type>
    <struct>medium</struct>
  </car>
</cars>

Right now chidley assumes that the XML sample it is given might be incomplete, and assumes that all tags:

  1. Might have an attribute in some other sample of the XML
  2. Might have child tag in some other samples of the XML

That is, while the following is XML provided:
<type>Honda</type>
chidley assumes that these might also exist:
<type type="foo">Honda</type>
or
<type><otherTag>Honda</otherTag></type>

And therefor generates additional structs instead of inlining strings:

type ChiCar struct {
ChiStruct *ChiStruct `xml:" struct,omitempty" json:"struct,omitempty"`
ChiType *ChiType `xml:" type,omitempty" json:"type,omitempty"`
}
type ChiCars struct {
ChiCar []*ChiCar `xml:" car,omitempty" json:"car,omitempty"`
}
type ChiStruct struct {
Text string `xml:",chardata" json:",omitempty"`
}

type ChiType struct {
Text string xml:",chardata" json:",omitempty"
}

If the user has provided sample XML that is complete, then the above is overkill.
The following should be generated instead:

type ChiCar struct {
ChiStruct string `xml:"struct,omitempty"`
ChiType string `xml:"type,omitempty"`
}
type ChiCars struct {
ChiCar []*ChiCar `xml:" car,omitempty" json:"car,omitempty"`
}

A command line argument should support this mode (false by default so as to not alter the default behaviour).

Duplicate struct field generation

I have a snippet of XML that does something weird with the generated struct:

<con1:actions>
   <con2:route xmlns:con2="http://www.bea.com/wli/sb/stages/routing/config">
     <con3:id xmlns:con3="http://www.bea.com/wli/sb/stages/config">_ActionId-3525062221263473230--64db5972.154ce25275c.-7fc5</con3:id>
     <con2:service ref="Something/Proxy/Something" xsi:type="ref:ProxyRef" xmlns:ref="http://www.bea.com/wli/sb/reference" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <con2:operation passThrough="true"/>
     <con2:outboundTransform/>
     <con2:responseTransform/>
   </con2:route>
</con1:actions>

Generates this struct, with the duplicated Attr_ref field:

type Chicon2_service struct {
	Attr_ref      string   `xml:" ref,attr"  json:",omitempty"`
	Attr_ref      string   `xml:"xmlns ref,attr"  json:",omitempty"`
	Attr_xsi_type string   `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr"  json:",omitempty"`
	Attr_xsi      string   `xml:"xmlns xsi,attr"  json:",omitempty"`
	XMLName       xml.Name `xml:"http://www.bea.com/wli/sb/stages/routing/config service,omitempty" json:"service,omitempty"`
}

Unable to build on Debian or OSX

When attempting to build Chidley, the following error is output for me:

chidley-master laptop$ GOOS=darwin GOARCH=amd64 go build chidley.go
# command-line-arguments
./chidley.go:218:29: undefined: Node
./chidley.go:218:105: undefined: FQN
./chidley.go:252:43: undefined: FQN
./chidley.go:300:79: undefined: Source
./chidley.go:367:29: undefined: Node
./chidley.go:367:70: undefined: FQN
./chidley.go:367:79: undefined: XMLType
./chidley.go:390:34: undefined: Node
./chidley.go:398:27: undefined: PrintGoStructVisitor
./chidley.go:419:34: undefined: PrintGoStructVisitor
./chidley.go:419:34: too many errors

Some potential helpful information regarding environment:

laptop$ go version
go version go1.10 darwin/amd64
laptop$
laptop$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/laptop/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/laptop/Development/Go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/41/jf6b3x3d63q5w5my6h16q_f80000gq/T/go-build296077778=/tmp/go-build -gno-record-gcc-switches -fno-common"

Support Xinclude

As a user, I would like to run chidley on XML files that contain statements like

<xi:include href="path/to/include/file.xml" />

and let chidley generate Go structs for the XML with all includes resolved.

Inconsistent ordering

chidley is a very useful tool.

I'm trying it for the first time, but have found that its out order is inconsistent. Is it so?

  • I tried to compare the output of two xml file of the same structure, but the outputs are incomparable because of the inconsistent ordering.
  • I then tried to compare the output of a single xml file, with and without -t switch, but the outputs are incomparable as well because of the inconsistent ordering.

Is it really so? Thx.

Type information of tags with -t flag does not work when collapsing tags with -F

When using both -t (use type information) and -F (collapse simple tags), only the collapsing is occurring, with no changes due to type information.

Example XML:data/typeCollapsing.xm

  <record>
    <name>Bill Smith</name>
    <age>42</age>
  </record>

No flags:

$chidley  data/typeCollapsing.xml 
type Cage struct {
	XMLName xml.Name`xml:"age,omitempty" json:"age,omitempty"`
	Text string `xml:",chardata" json:",omitempty"`
}

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

type Crecord struct {
	XMLName xml.Name`xml:"record,omitempty" json:"record,omitempty"`
	Cage *Cage `xml:"age,omitempty" json:"age,omitempty"`
	Cname *Cname `xml:"name,omitempty" json:"name,omitempty"`
}

This is correct.

Use type information -t:

$chidley  -t data/typeCollapsing.xml 
type Cage struct {
	XMLName xml.Name`xml:"age,omitempty" json:"age,omitempty"`
	Number int8 `xml:",chardata" json:",omitempty"`
}

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

type Crecord struct {
	XMLName xml.Name`xml:"record,omitempty" json:"record,omitempty"`
	Cage *Cage `xml:"age,omitempty" json:"age,omitempty"`
	Cname *Cname `xml:"name,omitempty" json:"name,omitempty"`
}

Note in Cage Number int8 instead of Cage Text string
This is correct.

Collapse tags:

$chidley  -F data/typeCollapsing.xml 
type Crecord struct {
	XMLName xml.Name`xml:"record,omitempty" json:"record,omitempty"`
	Cage string `xml:"age,omitempty" json:"age,omitempty"`
	Cname string `xml:"name,omitempty" json:"name,omitempty"`
}

Cage and Cname are now variable fields not struct fields.
This is correct.

Collapse with type information:

$chidley  -F -t data/typeCollapsing.xml 
type Crecord struct {
	XMLName xml.Name`xml:"record,omitempty" json:"record,omitempty"`
	Cage string `xml:"age,omitempty" json:"age,omitempty"`
	Cname string `xml:"name,omitempty" json:"name,omitempty"`
}

This is not correct.
Cage string should be Cage int8

generate go structs with camelCase instead of Chicamel_case

This is a nice tool, and does save me some effort. That said, I'd like to be able to generate according to the suggestions provided by golint to be compatible with the community conventions. For one small example, I have a stub that turns out to look like so:

type Chixml_fragment struct {
	Chiser_coreEntry      *Chiser_coreEntry      `xml:"http://www.bea.com/wli/sb/services coreEntry,omitempty" json:"coreEntry,omitempty"`
	Chiser_endpointConfig *Chiser_endpointConfig `xml:"http://www.bea.com/wli/sb/services endpointConfig,omitempty" json:"endpointConfig,omitempty"`
	Chiser_router         *Chiser_router         `xml:"http://www.bea.com/wli/sb/services router,omitempty" json:"router,omitempty"`
}

But, it has a couple lint errors:

exported type Chixml_fragment should have comment or be unexported (golint)
don't use underscores in Go names; type Chixml_fragment should be ChixmlFragment (golint)

This gets much, much worse as you expand out, and the linter stops reporting after the first 70+ errors that it finds, all related to those two errors.

I would like to be able to specify a camelCase convention for struct naming. Right now, OOTB, it generates an exported struct, which doesn't have documentation, and also includes underscores _ when it's not a convention used in Go.

Other than that, this thing works great!

Unmarshal error with namespaced and non-namespaced XML Attributes

You're probably loving all of these issues...Sorry about that.

I found something that I'm not sure if it's a Go encoding/xml error, or if there's something wrong with my XML. The following piece of XML

<ser:binding type="SOAP" isSoap12="false" xsi:type="con:SoapBindingType" xmlns:con="http://www.bea.com/wli/sb/services/bindings/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- other nested items -->
...
</ser:binding>

Generates the following struct:

type Chiser_binding struct {
	Attr_con             string                `xml:"xmlns con,attr"  json:",omitempty"`
	Attr_isSoap12        string                `xml:"isSoap12,attr"  json:",omitempty"`
	Attr_type            string                `xml:" type,attr"  json:",omitempty"`
	Attr_xsi_type        string                `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr"  json:",omitempty"`
	Attr_xsi             string                `xml:"xmlns xsi,attr"  json:",omitempty"`
	Chicon_WSI_compliant *Chicon_WSI_compliant `xml:"http://www.bea.com/wli/sb/services/bindings/config WSI-compliant,omitempty" json:"WSI-compliant,omitempty"`
	Chicon_port          *Chicon_port          `xml:"http://www.bea.com/wli/sb/services/bindings/config port,omitempty" json:"port,omitempty"`
	Chicon_selector      *Chicon_selector      `xml:"http://www.bea.com/wli/sb/services/bindings/config selector,omitempty" json:"selector,omitempty"`
	Chicon_wsdl          *Chicon_wsdl          `xml:"http://www.bea.com/wli/sb/services/bindings/config wsdl,omitempty" json:"wsdl,omitempty"`
	XMLName              xml.Name              `xml:"http://www.bea.com/wli/sb/services binding,omitempty" json:"binding,omitempty"`
}

However, when I unmarshal, I get the following error:

proxy_test.go:18: lint.Chiser_binding field "Attr_type" with tag " type,attr" conflicts with field "Attr_xsi_type" with tag "http://www.w3.org/2001/XMLSchema-instance type,attr"

encoding "windows-1251" declared but Decoder.CharsetReader

2017/03/02 14:42:29 extractor.go:58: xml: encoding "windows-1251" declared but Decoder.CharsetReader is nil
2017/03/02 14:42:29 chidley.go:151: FATAL ERROR: xml: encoding "windows-1251" declared but Decoder.CharsetReader is nil

for file like

<?xml version="1.0" encoding="windows-1251"?>
<data status="ok"><cont...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.