xgen

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2023 License: BSD-3-Clause Imports: 17 Imported by: 0

README

xgen logo


Build Status Code Coverage Go Report Card go.dev Licenses Donate

xgen

Introduction

xgen is a library written in pure Go providing a set of functions that allow you to parse XSD (XML schema definition) files. This library needs Go version 1.10 or later. The full API docs can be seen using go's built-in documentation tool, or online at go.dev.

xgen commands automatically compiles XML schema files into the multi-language type or class declarations code.

Install the command line tool first.

If you're using Go 1.17 and later, installing executables with go install

go install github.com/xuri/xgen/cmd/xgen@latest

If you're using Go 1.16 and earlier, installing executables with go get

go get -u -v github.com/dmytro-vovk-f3/xgen/cmd/...

The command below will walk on the xsd path and generate Go language struct code under the output directory.

$ xgen -i /path/to/your/xsd -o /path/to/your/output -l Go

Usage:

$ xgen [<flag> ...] <XSD file or directory> ...
   -i <path> Input file path or directory for the XML schema definition
   -o <path> Output file path or directory for the generated code
   -p        Specify the package name
   -l        Specify the language of generated code (Go/C/Java/Rust/TypeScript)
   -h        Output this help and exit
   -v        Output version and exit

XSD (XML Schema Definition)

XSD, a recommendation of the World Wide Web Consortium (W3C), specifies how to formally describe the elements in an Extensible Markup Language (XML) document. It can be used by programmers to verify each piece of item content in a document. They can check if it adheres to the description of the element it is placed in.

XSD can be used to express a set of rules to which an XML document must conform in order to be considered "valid" according to that schema. However, unlike most other schema languages, XSD was also designed with the intent that determination of a document's validity would produce a collection of information adhering to specific data types. Such a post-validation infoset can be useful in the development of XML document processing software.

Contributing

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change. XSD is compliant with XML Schema Part 1: Structures Second Edition.

Licenses

This program is under the terms of the BSD 3-Clause License. See https://opensource.org/licenses/BSD-3-Clause.

Logo is designed by xuri. Licensed under the Creative Commons 3.0 Attributions license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltInTypes = map[string][]string{
	"anyType":            {"string", "string", "char", "String", "String"},
	"ENTITIES":           {"[]string", "Array<string>", "char[]", "List<String>", "Vec<String>"},
	"ENTITY":             {"string", "string", "char", "String", "String"},
	"ID":                 {"string", "string", "char", "String", "String"},
	"IDREF":              {"string", "string", "char", "String", "String"},
	"IDREFS":             {"[]string", "Array<string>", "char[]", "List<String>", "Vec<String>"},
	"NCName":             {"string", "string", "char", "String", "String"},
	"NMTOKEN":            {"string", "string", "char", "String", "String"},
	"NMTOKENS":           {"[]string", "Array<string>", "char[]", "List<String>", "Vec<String>"},
	"NOTATION":           {"[]string", "Array<string>", "char[]", "List<String>", "Vec<String>"},
	"Name":               {"string", "string", "char", "String", "String"},
	"QName":              {"xml.Name", "any", "char", "String", "String"},
	"anyURI":             {"string", "string", "char", "QName", "String"},
	"base64Binary":       {"string", "Uint8Array", "char[]", "List<Byte>", "String"},
	"boolean":            {"bool", "boolean", "bool", "Boolean", "bool"},
	"byte":               {"int8", "any", "char[]", "Byte", "u8"},
	"date":               {"string", "string", "char", "String", "u8"},
	"dateTime":           {"string", "string", "char", "String", "u8"},
	"decimal":            {"float64", "number", "float", "Float", "f64"},
	"double":             {"float64", "number", "float", "Float", "f64"},
	"duration":           {"string", "string", "char", "String", "String"},
	"float":              {"float32", "number", "float", "Float", "f64"},
	"gDay":               {"string", "string", "char", "String", "String"},
	"gMonth":             {"string", "string", "char", "String", "String"},
	"gMonthDay":          {"string", "string", "char", "String", "String"},
	"gYear":              {"string", "string", "char", "String", "String"},
	"gYearMonth":         {"string", "string", "char", "String", "String"},
	"hexBinary":          {"string", "Uint8Array", "char[]", "List<Byte>", "String"},
	"int":                {"int", "number", "int", "Integer", "i32"},
	"integer":            {"int", "number", "int", "Integer", "i32"},
	"language":           {"string", "string", "char", "String", "String"},
	"long":               {"int64", "number", "int", "Long", "i64"},
	"negativeInteger":    {"int", "number", "int", "Integer", "i32"},
	"nonNegativeInteger": {"int", "number", "int", "Integer", "u32"},
	"normalizedString":   {"string", "string", "char", "String", "String"},
	"nonPositiveInteger": {"int", "number", "int", "Integer", "i32"},
	"positiveInteger":    {"int", "number", "int", "Integer", "u32"},
	"short":              {"int16", "number", "int", "Integer", "i16"},
	"string":             {"string", "string", "char", "String", "String"},
	"time":               {"time.Time", "string", "char", "String", "String"},
	"token":              {"string", "string", "char", "String", "String"},
	"unsignedByte":       {"uint8", "any", "char", "Byte", "u8"},
	"unsignedInt":        {"uint32", "number", "unsigned int", "Integer", "u32"},
	"unsignedLong":       {"uint64", "number", "unsigned int", "Long", "u64"},
	"unsignedShort":      {"uint16", "number", "unsigned int", "Short", "u16"},
	"xml:lang":           {"string", "string", "char", "String", "String"},
	"xml:space":          {"string", "string", "char", "String", "String"},
	"xml:base":           {"string", "string", "char", "String", "String"},
	"xml:id":             {"string", "string", "char", "String", "String"},
}

BuiltInTypes defines the correspondence between Go, TypeScript, C, Java, Rust languages and data types in XSD. https://www.w3.org/TR/xmlschema-2/#datatype

Functions

func GetFileList

func GetFileList(path string) (files []string, err error)

GetFileList get a list of file by given path.

func MakeFirstUpperCase

func MakeFirstUpperCase(s string) string

MakeFirstUpperCase make the first letter of a string uppercase.

func PrepareOutputDir

func PrepareOutputDir(path string) error

PrepareOutputDir provide a method to create the output directory by given path.

func ToSnakeCase

func ToSnakeCase(input string) string

ToSnakeCase converts the provided string to snake_case.

func ToTitle

func ToTitle(val string) string

Types

type Attribute

type Attribute struct {
	Name     string
	Doc      string
	Type     string
	Plural   bool
	Default  string
	Optional bool
}

Attribute declarations provide for: Local validation of attribute information item values using a simple type definition; Specifying default or fixed values for attribute information items. https://www.w3.org/TR/xmlschema-1/structures.html#element-attribute

type AttributeGroup

type AttributeGroup struct {
	Doc        string
	Name       string
	Ref        string
	Attributes []Attribute
}

AttributeGroup definitions do not participate in ·validation· as such, but the {attribute uses} and {attribute wildcard} of one or more complex type definitions may be constructed in whole or part by reference to an attribute group. Thus, attribute group definitions provide a replacement for some uses of XML's parameter entity facility. Attribute group definitions are provided primarily for reference from the XML representation of schema components (see <complexType> and <attributeGroup>). https://www.w3.org/TR/xmlschema-1/structures.html#Attribute_Group_Definition

type Choice

type Choice struct {
	ID     string
	Choice []Choice
	Plural bool
}

Choice definitions are provided primarily for reference from the XML Representation of Choice Definitions which acts as a container stating that one and only one element in the selected group should be present in the containing element. Generated code does not enforce the "one and only one" constraint but the choice container is parsed in order to effectively define if the elements it contains should be plural or not (as defined by the maxOccurs). https://www.w3.org/TR/xmlschema-1/#Complex_Type_Definition_details

type CodeGenerator

type CodeGenerator struct {
	Lang              string
	File              string
	Field             string
	Package           string
	ImportTime        bool // For Go language
	ImportEncodingXML bool // For Go language
	SkipXMLNames      bool
	ProtoTree         []interface{}
	StructAST         map[string]string
}

CodeGenerator holds code generator overrides and runtime data that are used when generate code from proto tree.

func (*CodeGenerator) CAttribute

func (gen *CodeGenerator) CAttribute(v *Attribute)

CAttribute generates code for attribute XML schema in C language syntax.

func (*CodeGenerator) CAttributeGroup

func (gen *CodeGenerator) CAttributeGroup(v *AttributeGroup)

CAttributeGroup generates code for attribute group XML schema in C language syntax.

func (*CodeGenerator) CComplexType

func (gen *CodeGenerator) CComplexType(v *ComplexType)

CComplexType generates code for complex type XML schema in C language syntax.

func (*CodeGenerator) CElement

func (gen *CodeGenerator) CElement(v *Element)

CElement generates code for element XML schema in C language syntax.

func (*CodeGenerator) CGroup

func (gen *CodeGenerator) CGroup(v *Group)

CGroup generates code for group XML schema in C language syntax.

func (*CodeGenerator) CSimpleType

func (gen *CodeGenerator) CSimpleType(v *SimpleType)

CSimpleType generates code for simple type XML schema in C language syntax.

func (*CodeGenerator) GenC

func (gen *CodeGenerator) GenC() error

GenC generates C programming language source code for XML schema definition files.

func (*CodeGenerator) GenGo

func (gen *CodeGenerator) GenGo() error

GenGo generate Go programming language source code for XML schema definition files.

func (*CodeGenerator) GenJava

func (gen *CodeGenerator) GenJava() error

GenJava generate Java programming language source code for XML schema definition files.

func (*CodeGenerator) GenRust

func (gen *CodeGenerator) GenRust() error

GenRust generate Go programming language source code for XML schema definition files.

func (*CodeGenerator) GenTypeScript

func (gen *CodeGenerator) GenTypeScript() error

GenTypeScript generate TypeScript programming language source code for XML schema definition files.

func (*CodeGenerator) GoAttribute

func (gen *CodeGenerator) GoAttribute(v *Attribute)

GoAttribute generates code for attribute XML schema in Go language syntax.

func (*CodeGenerator) GoAttributeGroup

func (gen *CodeGenerator) GoAttributeGroup(v *AttributeGroup)

GoAttributeGroup generates code for attribute group XML schema in Go language syntax.

func (*CodeGenerator) GoComplexType

func (gen *CodeGenerator) GoComplexType(v *ComplexType)

GoComplexType generates code for complex type XML schema in Go language syntax.

func (*CodeGenerator) GoElement

func (gen *CodeGenerator) GoElement(v *Element)

GoElement generates code for element XML schema in Go language syntax.

func (*CodeGenerator) GoGroup

func (gen *CodeGenerator) GoGroup(v *Group)

GoGroup generates code for group XML schema in Go language syntax.

func (*CodeGenerator) GoSimpleType

func (gen *CodeGenerator) GoSimpleType(v *SimpleType)

GoSimpleType generates code for simple type XML schema in Go language syntax.

func (*CodeGenerator) JavaAttribute

func (gen *CodeGenerator) JavaAttribute(v *Attribute)

JavaAttribute generates code for attribute XML schema in Java language syntax.

func (*CodeGenerator) JavaAttributeGroup

func (gen *CodeGenerator) JavaAttributeGroup(v *AttributeGroup)

JavaAttributeGroup generates code for attribute group XML schema in Java language syntax.

func (*CodeGenerator) JavaComplexType

func (gen *CodeGenerator) JavaComplexType(v *ComplexType)

JavaComplexType generates code for complex type XML schema in Java language syntax.

func (*CodeGenerator) JavaElement

func (gen *CodeGenerator) JavaElement(v *Element)

JavaElement generates code for element XML schema in Java language syntax.

func (*CodeGenerator) JavaGroup

func (gen *CodeGenerator) JavaGroup(v *Group)

JavaGroup generates code for group XML schema in Java language syntax.

func (*CodeGenerator) JavaSimpleType

func (gen *CodeGenerator) JavaSimpleType(v *SimpleType)

JavaSimpleType generates code for simple type XML schema in Java language syntax.

func (*CodeGenerator) RustAttribute

func (gen *CodeGenerator) RustAttribute(v *Attribute)

RustAttribute generates code for attribute XML schema in Rust language syntax.

func (*CodeGenerator) RustAttributeGroup

func (gen *CodeGenerator) RustAttributeGroup(v *AttributeGroup)

RustAttributeGroup generates code for attribute group XML schema in Rust language syntax.

func (*CodeGenerator) RustComplexType

func (gen *CodeGenerator) RustComplexType(v *ComplexType)

RustComplexType generates code for complex type XML schema in Rust language syntax.

func (*CodeGenerator) RustElement

func (gen *CodeGenerator) RustElement(v *Element)

RustElement generates code for element XML schema in Rust language syntax.

func (*CodeGenerator) RustGroup

func (gen *CodeGenerator) RustGroup(v *Group)

RustGroup generates code for group XML schema in Rust language syntax.

func (*CodeGenerator) RustSimpleType

func (gen *CodeGenerator) RustSimpleType(v *SimpleType)

RustSimpleType generates code for simple type XML schema in Rust language syntax.

func (*CodeGenerator) TypeScriptAttribute

func (gen *CodeGenerator) TypeScriptAttribute(v *Attribute)

TypeScriptAttribute generates code for attribute XML schema in TypeScript language syntax.

func (*CodeGenerator) TypeScriptAttributeGroup

func (gen *CodeGenerator) TypeScriptAttributeGroup(v *AttributeGroup)

TypeScriptAttributeGroup generates code for attribute group XML schema in TypeScript language syntax.

func (*CodeGenerator) TypeScriptComplexType

func (gen *CodeGenerator) TypeScriptComplexType(v *ComplexType)

TypeScriptComplexType generates code for complex type XML schema in TypeScript language syntax.

func (*CodeGenerator) TypeScriptElement

func (gen *CodeGenerator) TypeScriptElement(v *Element)

TypeScriptElement generates code for element XML schema in TypeScript language syntax.

func (*CodeGenerator) TypeScriptGroup

func (gen *CodeGenerator) TypeScriptGroup(v *Group)

TypeScriptGroup generates code for group XML schema in TypeScript language syntax.

func (*CodeGenerator) TypeScriptSimpleType

func (gen *CodeGenerator) TypeScriptSimpleType(v *SimpleType)

TypeScriptSimpleType generates code for simple type XML schema in TypeScript language syntax.

type ComplexType

type ComplexType struct {
	Doc            string
	Name           string
	Base           string
	Anonymous      bool
	Elements       []Element
	Attributes     []Attribute
	Groups         []Group
	Choice         []Choice
	AttributeGroup []AttributeGroup
	Mixed          bool
}

ComplexType definitions are identified by their {name} and {target namespace}. Except for anonymous complex type definitions (those with no {name}), since type definitions (i.e. both simple and complex type definitions taken together) must be uniquely identified within an ·XML Schema·, no complex type definition can have the same name as another simple or complex type definition. Complex type {name}s and {target namespace}s are provided for reference from instances, and for use in the XML representation of schema components (specifically in <element>). See References to schema components across namespaces for the use of component identifiers when importing one schema into another. https://www.w3.org/TR/xmlschema-1/structures.html#element-complexType

type Element

type Element struct {
	Doc      string
	Name     string
	Wildcard bool
	Type     string
	Abstract bool
	Plural   bool
	Optional bool
	Nillable bool
	Default  string
}

Element declarations provide for: Local validation of element information item values using a type definition; Specifying default or fixed values for an element information items; Establishing uniquenesses and reference constraint relationships among the values of related elements and attributes; Controlling the substitutability of elements through the mechanism of element substitution groups. https://www.w3.org/TR/xmlschema-1/#cElement_Declarations

type Group

type Group struct {
	Doc      string
	Name     string
	Elements []Element
	Groups   []Group
	Plural   bool
	Ref      string
}

Group (model group) definitions are provided primarily for reference from the XML Representation of Complex Type Definitions. Thus, model group definitions provide a replacement for some uses of XML's parameter entity facility. https://www.w3.org/TR/xmlschema-1/structures.html#cModel_Group_Definitions

type Options

type Options struct {
	FilePath            string
	FileDir             string
	InputDir            string
	OutputDir           string
	Extract             bool
	Lang                string
	Package             string
	IncludeMap          map[string]bool
	LocalNameNSMap      map[string]string
	NSSchemaLocationMap map[string]string
	ParseFileList       map[string]bool
	ParseFileMap        map[string][]interface{}
	ProtoTree           []interface{}
	RemoteSchema        map[string][]byte

	InElement        string
	CurrentEle       string
	InGroup          int
	InUnion          bool
	InAttributeGroup bool
	SkipXMLNames     bool

	SimpleType     *Stack
	ComplexType    *Stack
	Element        *Stack
	Attribute      *Stack
	Group          *Stack
	AttributeGroup *Stack
	Choice         *Stack
}

Options holds user-defined overrides and runtime data that are used when parsing from an XSD document.

func NewParser

func NewParser(options *Options) *Options

NewParser creates a new parser options for the Parse. Useful for XML schema parsing.

func (*Options) EndAttribute

func (opt *Options) EndAttribute(ele xml.EndElement, protoTree []interface{}) (err error)

EndAttribute handles parsing event on the attribute end elements.

func (*Options) EndAttributeGroup

func (opt *Options) EndAttributeGroup(ele xml.EndElement, protoTree []interface{}) (err error)

EndAttributeGroup handles parsing event on the attributeGroup end elements.

func (*Options) EndChoice

func (opt *Options) EndChoice(xml.EndElement, []interface{}) (err error)

EndChoice handles parsing event on the choice end elements.

func (*Options) EndComplexType

func (opt *Options) EndComplexType(_ xml.EndElement, _ []interface{}) (err error)

EndComplexType handles parsing event on the complex end elements.

func (*Options) EndElement

func (opt *Options) EndElement(ele xml.EndElement, protoTree []interface{}) (err error)

EndElement handles parsing event on the element end elements.

func (*Options) EndEnumeration

func (opt *Options) EndEnumeration(ele xml.EndElement, protoTree []interface{}) (err error)

EndEnumeration handles parsing event on the enumeration end elements. Enumeration defines a list of acceptable values.

func (*Options) EndExtension

func (opt *Options) EndExtension(ele xml.EndElement, protoTree []interface{}) (err error)

EndExtension handles parsing event on the extension end elements.

func (*Options) EndFractionDigits

func (opt *Options) EndFractionDigits(ele xml.EndElement, protoTree []interface{}) (err error)

EndFractionDigits handles parsing event on the fractionDigits end elements. Enumeration Defines a list of acceptable values. FractionDigits specifies the maximum number of decimal places allowed. Must be equal to or greater than zero.

func (*Options) EndGroup

func (opt *Options) EndGroup(ele xml.EndElement, protoTree []interface{}) (err error)

EndGroup handles parsing event on the group end elements.

func (*Options) EndLength

func (opt *Options) EndLength(ele xml.EndElement, protoTree []interface{}) (err error)

EndLength handles parsing event on the length end elements. Length specifies the exact number of characters or list items allowed. Must be equal to or greater than zero.

func (*Options) EndMaxExclusive

func (opt *Options) EndMaxExclusive(ele xml.EndElement, protoTree []interface{}) (err error)

EndMaxExclusive handles parsing event on the maxExclusive end elements. MaxExclusive specifies the upper bounds for numeric values (the value must be less than this value).

func (*Options) EndMaxInclusive

func (opt *Options) EndMaxInclusive(ele xml.EndElement, protoTree []interface{}) (err error)

EndMaxInclusive handles parsing event on the maxInclusive end elements. MaxInclusive specifies the upper bounds for numeric values (the value must be less than or equal to this value).

func (*Options) EndMaxLength

func (opt *Options) EndMaxLength(ele xml.EndElement, protoTree []interface{}) (err error)

EndMaxLength handles parsing event on the maxLength end elements. MaxLength specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero.

func (*Options) EndMinExclusive

func (opt *Options) EndMinExclusive(ele xml.EndElement, protoTree []interface{}) (err error)

EndMinExclusive handles parsing event on the minExclusive end elements. MinExclusive specifies the lower bounds for numeric values (the value must be greater than this value).

func (*Options) EndMinInclusive

func (opt *Options) EndMinInclusive(ele xml.EndElement, protoTree []interface{}) (err error)

EndMinInclusive handles parsing event on the minInclusive end elements. MinInclusive specifies the lower bounds for numeric values (the value must be greater than or equal to this value).

func (*Options) EndMinLength

func (opt *Options) EndMinLength(ele xml.EndElement, protoTree []interface{}) (err error)

EndMinLength handles parsing event on the minLength end elements. MinLength specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero.

func (*Options) EndPattern

func (opt *Options) EndPattern(ele xml.EndElement, protoTree []interface{}) (err error)

EndPattern handles parsing event on the pattern end elements. Pattern defines the exact sequence of characters that are acceptable.

func (*Options) EndRestriction

func (opt *Options) EndRestriction(ele xml.EndElement, protoTree []interface{}) (err error)

EndRestriction handles parsing event on the restriction end elements.

func (*Options) EndSimpleType

func (opt *Options) EndSimpleType(ele xml.EndElement, protoTree []interface{}) (err error)

EndSimpleType handles parsing event on the simpleType end elements.

func (*Options) EndTotalDigits

func (opt *Options) EndTotalDigits(ele xml.EndElement, protoTree []interface{}) (err error)

EndTotalDigits handles parsing event on the totalDigits end elements. TotalDigits specifies the exact number of digits allowed. Must be greater than zero.

func (*Options) EndUnion

func (opt *Options) EndUnion(ele xml.EndElement, protoTree []interface{}) (err error)

EndUnion handles parsing event on the union end elements.

func (*Options) EndWhiteSpace

func (opt *Options) EndWhiteSpace(ele xml.EndElement, protoTree []interface{}) (err error)

EndWhiteSpace handles parsing event on the whiteSpace end elements. WhiteSpace specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled.

func (*Options) GetValueType

func (opt *Options) GetValueType(value string, XSDSchema []interface{}) (valueType string, err error)

GetValueType convert XSD schema value type to the build-in type for the given value and proto tree.

func (*Options) OnAttribute

func (opt *Options) OnAttribute(ele xml.StartElement, protoTree []interface{}) (err error)

OnAttribute handles parsing event on the attribute start elements. All attributes are declared as simple types.

func (*Options) OnAttributeGroup

func (opt *Options) OnAttributeGroup(ele xml.StartElement, protoTree []interface{}) (err error)

OnAttributeGroup handles parsing event on the attributeGroup start elements. The attributeGroup element is used to group a set of attribute declarations so that they can be incorporated as a group into complex type definitions.

func (*Options) OnCharData

func (opt *Options) OnCharData(ele string, protoTree []interface{}) (err error)

OnCharData handles parsing event on the documentation start elements. The documentation element specifies information to be read or used by users within an annotation element.

func (*Options) OnChoice

func (opt *Options) OnChoice(ele xml.StartElement, _ []interface{}) (err error)

OnChoice handles parsing event on the choice start elements. The choice element defines that one and only one of the contained element can be present within the contained element.

func (*Options) OnComplexType

func (opt *Options) OnComplexType(ele xml.StartElement, _ []interface{}) (err error)

OnComplexType handles parsing event on the complex start elements. A complex element contains other elements and/or attributes.

func (*Options) OnElement

func (opt *Options) OnElement(ele xml.StartElement, protoTree []interface{}) (err error)

OnElement handles parsing event on the element start elements.

func (*Options) OnEnumeration

func (opt *Options) OnEnumeration(ele xml.StartElement, protoTree []interface{}) (err error)

OnEnumeration handles parsing event on the enumeration start elements.

func (*Options) OnExtension

func (opt *Options) OnExtension(ele xml.StartElement, protoTree []interface{}) (err error)

OnExtension handles parsing event on the extension start elements. The extension element defines a base class for a complexType or simpleContent.

func (*Options) OnGroup

func (opt *Options) OnGroup(ele xml.StartElement, protoTree []interface{}) (err error)

OnGroup handles parsing event on the group start elements. The group element is used to define a group of elements to be used in complex type definitions.

func (*Options) OnImport

func (opt *Options) OnImport(ele xml.StartElement, protoTree []interface{}) (err error)

OnImport handles parsing event on the import start elements. The list element defines a simple type element as a list of values of a specified data type.

func (*Options) OnInclude

func (opt *Options) OnInclude(ele xml.StartElement, protoTree []interface{}) (err error)

OnInclude handles parsing event on the include start elements. The list element defines a simple type element as a list of values of a specified data type.

func (*Options) OnList

func (opt *Options) OnList(ele xml.StartElement, protoTree []interface{}) (err error)

OnList handles parsing event on the list start elements. The list element defines a simple type element as a list of values of a specified data type.

func (*Options) OnRestriction

func (opt *Options) OnRestriction(ele xml.StartElement, protoTree []interface{}) (err error)

OnRestriction handles parsing event on the restriction start elements. The restriction element defines restrictions on a simpleType, simpleContent, or complexContent definition.

func (*Options) OnSchema

func (opt *Options) OnSchema(ele xml.StartElement, protoTree []interface{}) (err error)

OnSchema handles parsing event on the schema start elements. Schema is the root element of every XML Schema.

func (*Options) OnSimpleType

func (opt *Options) OnSimpleType(ele xml.StartElement, protoTree []interface{}) (err error)

OnSimpleType handles parsing event on the simpleType start elements. The simpleType element defines a simple type and specifies the constraints and information about the values of attributes or text-only elements.

func (*Options) OnUnion

func (opt *Options) OnUnion(ele xml.StartElement, protoTree []interface{}) (err error)

OnUnion handles parsing event on the union start elements. The union element defines a simple type as a collection (union) of values from specified simple data types.

func (*Options) Parse

func (opt *Options) Parse() (err error)

Parse reads XML documents and return proto tree for every element in the documents by given options. If value of the property extract is false, parse will fetch schema used in <import> or <include> statements.

type Restriction

type Restriction struct {
	Doc                  string
	Precision            int
	Enum                 []string
	Min, Max             float64
	MinLength, MaxLength int
	Pattern              *regexp.Regexp
}

Restriction are used to define acceptable values for XML elements or attributes. Restriction on XML elements are called facets. https://www.w3.org/TR/xmlschema-1/structures.html#element-restriction

type SimpleType

type SimpleType struct {
	Doc         string
	Name        string
	Base        string
	Anonymous   bool
	List        bool
	Union       bool
	MemberTypes map[string]string
	Restriction Restriction
}

SimpleType definitions provide for constraining character information item [children] of element and attribute information items. https://www.w3.org/TR/xmlschema-1/#Simple_Type_Definitions

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack defined an abstract data type that serves as a collection of elements

func NewStack

func NewStack() *Stack

NewStack create a new stack

func (*Stack) Empty

func (stack *Stack) Empty() bool

Empty the stack

func (*Stack) Len

func (stack *Stack) Len() int

Len return the number of items in the stack

func (*Stack) Peek

func (stack *Stack) Peek() interface{}

Peek view the top item on the stack

func (*Stack) Pop

func (stack *Stack) Pop() interface{}

Pop the top item of the stack and return it

func (*Stack) Push

func (stack *Stack) Push(value interface{})

Push a value onto the top of the stack

Directories

Path Synopsis
cmd
test
go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL