本文整理匯總了Golang中github.com/rilinor/go-xml/xsdgen.Config.Option方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.Option方法的具體用法?Golang Config.Option怎麽用?Golang Config.Option使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rilinor/go-xml/xsdgen.Config
的用法示例。
在下文中一共展示了Config.Option方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleIgnoreElements
func ExampleIgnoreElements() {
doc := xsdfile(`
<complexType name="Person">
<sequence>
<element name="name" type="xs:string" />
<element name="deceased" type="soapenc:boolean" />
<element name="private" type="xs:int" />
</sequence>
</complexType>
`)
var cfg xsdgen.Config
cfg.Option(
xsdgen.IgnoreElements("private"),
xsdgen.IgnoreAttributes("id", "href"))
out, err := cfg.GenSource(doc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
// Output: package ws
//
// type Person struct {
// Name string `xml:"http://www.example.com/ name"`
// Deceased bool `xml:"http://www.example.com/ deceased"`
// }
}
示例2: ExampleUseFieldNames
func ExampleUseFieldNames() {
doc := xsdfile(`
<complexType name="library">
<sequence>
<element name="book" maxOccurs="unbounded">
<complexType>
<all>
<element name="title" type="xs:string" />
<element name="published" type="xs:date" />
<element name="author" type="xs:string" />
</all>
</complexType>
</element>
</sequence>
</complexType>`)
var cfg xsdgen.Config
cfg.Option(xsdgen.UseFieldNames())
out, err := cfg.GenSource(doc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
// Output: package ws
//
// import (
// "bytes"
// "time"
// )
//
// type Book struct {
// Title string `xml:"http://www.example.com/ title"`
// Published xsdDate `xml:"http://www.example.com/ published"`
// Author string `xml:"http://www.example.com/ author"`
// }
// type Library struct {
// Book []Book `xml:"http://www.example.com/ book"`
// Title string `xml:"http://www.example.com/ title"`
// Published xsdDate `xml:"http://www.example.com/ published"`
// Author string `xml:"http://www.example.com/ author"`
// }
// type xsdDate time.Time
//
// func (t *xsdDate) UnmarshalText(text []byte) error {
// return _unmarshalTime(text, (*time.Time)(t), "2006-01-02")
// }
// func (t *xsdDate) MarshalText() ([]byte, error) {
// return []byte((*time.Time)(t).Format("2006-01-02")), nil
// }
// func _unmarshalTime(text []byte, t *time.Time, format string) (err error) {
// s := string(bytes.TrimSpace(text))
// *t, err = time.Parse(format, s)
// if _, ok := err.(*time.ParseError); ok {
// *t, err = time.Parse(format+"Z07:00", s)
// }
// return err
// }
}
示例3: ExampleHandleSOAPArrayType
func ExampleHandleSOAPArrayType() {
doc := xsdfile(`
<complexType name="BoolArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xs:boolean[]"/>
</restriction>
</complexContent>
</complexType>`)
var cfg xsdgen.Config
cfg.Option(xsdgen.HandleSOAPArrayType())
out, err := cfg.GenSource(doc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
// Output: package ws
//
// type BoolArray struct {
// Offset ArrayCoordinate `xml:"offset,attr"`
// Id string `xml:"id,attr"`
// Href string `xml:"href,attr"`
// Items []bool `xml:",any"`
// }
}
示例4: ExampleSOAPArrayAsSlice
func ExampleSOAPArrayAsSlice() {
doc := xsdfile(`
<complexType name="BoolArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xs:boolean[]"/>
</restriction>
</complexContent>
</complexType>`)
var cfg xsdgen.Config
cfg.Option(
xsdgen.HandleSOAPArrayType(),
xsdgen.SOAPArrayAsSlice(),
xsdgen.IgnoreAttributes("offset", "id", "href"))
out, err := cfg.GenSource(doc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
// Output: package ws
//
// import "encoding/xml"
//
// type BoolArray []bool
//
// func (a *BoolArray) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// tag := xml.StartElement{Name: xml.Name{"", "item"}}
// for _, elt := range *a {
// if err := e.EncodeElement(elt, tag); err != nil {
// return err
// }
// }
// return nil
// }
// func (a *BoolArray) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
// var tok xml.Token
// var itemTag = xml.Name{"", ",any"}
// for tok, err = d.Token(); err == nil; tok, err = d.Token() {
// if tok, ok := tok.(xml.StartElement); ok {
// var item bool
// if itemTag.Local != ",any" && itemTag != tok.Name {
// err = d.Skip()
// continue
// }
// if err = d.DecodeElement(&item, &tok); err == nil {
// *a = append(*a, item)
// }
// }
// if _, ok := tok.(xml.EndElement); ok {
// break
// }
// }
// return err
// }
}
示例5: ExampleLogOutput
func ExampleLogOutput() {
var cfg xsdgen.Config
cfg.Option(
xsdgen.LogOutput(log.New(os.Stderr, "", 0)),
xsdgen.LogLevel(2))
if err := cfg.GenCLI("file.wsdl"); err != nil {
log.Fatal(err)
}
}
示例6: main
func main() {
log.SetFlags(0)
var cfg xsdgen.Config
cfg.Option(xsdgen.DefaultOptions...)
cfg.Option(xsdgen.LogOutput(log.New(os.Stderr, "", 0)))
if err := cfg.GenCLI(os.Args[1:]...); err != nil {
log.Fatal(err)
}
}
示例7: ExampleConfig_GenCLI
func ExampleConfig_GenCLI() {
var cfg xsdgen.Config
cfg.Option(
xsdgen.IgnoreAttributes("id", "href", "offset"),
xsdgen.IgnoreElements("comment"),
xsdgen.PackageName("webapi"),
xsdgen.Replace("_", ""),
xsdgen.HandleSOAPArrayType(),
xsdgen.SOAPArrayAsSlice(),
)
if err := cfg.GenCLI("webapi.xsd", "deps/soap11.xsd"); err != nil {
log.Fatal(err)
}
}
示例8: ExamplePackageName
func ExamplePackageName() {
doc := xsdfile(`
<simpleType name="zipcode">
<restriction base="xs:string">
<length value="10" />
</restriction>
</simpleType>
`)
var cfg xsdgen.Config
cfg.Option(xsdgen.PackageName("postal"))
out, err := cfg.GenSource(doc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
// Output: package postal
//
// type Zipcode string
}
示例9: ExampleIgnoreAttributes
func ExampleIgnoreAttributes() {
doc := xsdfile(`
<complexType name="ArrayOfString">
<any maxOccurs="unbounded" />
<attribute name="soapenc:arrayType" type="xs:string" />
</complexType>
`)
var cfg xsdgen.Config
cfg.Option(xsdgen.IgnoreAttributes("arrayType"))
out, err := cfg.GenSource(doc)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
// Output: package ws
//
// type ArrayOfString struct {
// Items []string `xml:",any"`
// }
}