Documentation ¶
Index ¶
- Variables
- func CreateNameFunc(upper []string) func(string) string
- type Node
- func (node *Node) ByName(name string) *Node
- func (node *Node) CreateOrGetChild(name xml.Name, attr []xml.Attr) *Node
- func (node *Node) End()
- func (node *Node) Height() int
- func (node *Node) IsMultivalued() bool
- func (node *Node) ReadFrom(r io.Reader) (int64, error)
- func (node *Node) ReadFromAll(readers []io.Reader) (n int64, err error)
- type Stack
- type StructWriter
Constants ¶
This section is empty.
Variables ¶
var ( // UppercaseByDefault is used during XML tag name to Go name conversion. UppercaseByDefault = []string{"id", "Id", "isbn", "ismn", "json", "eissn", "issn", "http", "lccn", "rfc", "rsn", "uri", "url", "urn", "xml", "Xml", "zdb"} // DefaultTextFieldNames list struct field names for chardata, most preferred first. DefaultTextFieldNames = []string{"Text", "Chardata"} // DefaultAttributePrefixes are used, if there are name clashes. DefaultAttributePrefixes = []string{"Attr", "Attribute"} )
var Version = "0.1.3"
Functions ¶
func CreateNameFunc ¶ added in v0.1.2
CreateNameFunc returns a function that converts a tag into a canonical Go name. Given list of strings will be wholly upper cased.
Types ¶
type Node ¶
type Node struct { Name xml.Name `json:"name,omitempty"` Attr []xml.Attr `json:"attr,omitempty"` Examples []string `json:"examples,omitempty"` Children []*Node `json:"children,omitempty"` Freqs []int `json:"-"` // Collect number of occurences of this node within parent. MaxExamples int `json:"-"` // Maximum number of examples to keep, gets passed to children. // contains filtered or unexported fields }
Node represents an element in the XML tree. It keeps track of its name, attributes, childnodes and example chardata and basic statistics, e.g. how often a node has been seen within its parent node.
func (*Node) ByName ¶ added in v0.1.2
ByName finds a node in the tree by name. Comparisons start at the current node. First match is returned. If nothing matches, nil is returned.
func (*Node) CreateOrGetChild ¶
CreateOrGetChild creates a child if no child with the same tag name exists, otherwise returns the existing node with that name. We want to collect node and attribute information for a node and not replicate the XML tree.
func (*Node) Height ¶
Height returns the height of the tree. A tree with zero nodes has height zero, a single node tree has height 1.
func (*Node) IsMultivalued ¶
IsMultivalued returns true, if this node appeared more than once.
type Stack ¶
Stack is a simple stack for arbitrary types.
func (*Stack) Peek ¶
func (s *Stack) Peek() interface{}
Peek returns the top element without removing it. Panic it stack is empty.
type StructWriter ¶
type StructWriter struct { NameFunc func(string) string // Turns xml tag names into Go names. TextFieldNames []string // Field name for chardata. AttributePrefixes []string // In case of a name clash, try these prefixes. WithComments bool // Annotate struct with comments and examples. Banner string // Autogenerated note. ExampleMaxChars int // Max length of example comment. Strict bool // Whether to ignore implementation holes. WithJSONTags bool // Include JSON struct tags. // contains filtered or unexported fields }
StructWriter can turn a node into a struct and can be configured.
func NewStructWriter ¶
func NewStructWriter(w io.Writer) *StructWriter
NewStructWriter can write a node to a given writer. Default list of abbreviations to wholly uppercase.
func (*StructWriter) WriteNode ¶
func (sw *StructWriter) WriteNode(node *Node) (err error)
WriteNode writes a node to a writer.