cxml

package
v0.0.0-...-91e9092 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAttribute

func GetAttribute(e xml.StartElement, name xml.Name) string

GetAttribute returns attribute value if it's present, otherwise it returns an empty string

func HasAttribute

func HasAttribute(e xml.StartElement, name xml.Name) bool

HasAttribute returns true if element has an attribute with given name, false otherwise

func Name

func Name(name string) xml.Name

Name returns an xml.Name with local part set to name

func NameEquals

func NameEquals(a, b xml.Name) bool

NameEquals return true if both namespaces and local names of nodes match, and false otherwise

func SetAttribute

func SetAttribute(e xml.StartElement, name, value string) xml.StartElement

SetAttribute is XML helper that allows to set attribute on a node

func TransformXML

func TransformXML(decoder *xml.Decoder, encoder *xml.Encoder, fn TransformFunc) error

TransformXML parses the XML tree, traverses it and calls TransformFunc on each XML token, writing the output to the writer, resulting in a transformed XML tree

func TrimSpace

func TrimSpace(parents *NodeList, in xml.Token) []xml.Token

TrimSpace is a transformer function that replaces CDATA with blank characters with empty strings

Types

type ConditionFunc

type ConditionFunc func(parents *NodeList, in xml.Token) bool

ConditionFunc is accepted by some transform function generators so they could be applied conditionally

func ParentIs

func ParentIs(name xml.Name) ConditionFunc

ParentIs is a functon that returns ConditionFunc checking if immediate parent's name matches name

type NodeList

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

func (*NodeList) ParentIs

func (n *NodeList) ParentIs(a xml.Name) bool

ParentIs returns true if last element exists and it's name equals to this name

func (*NodeList) Pop

func (n *NodeList) Pop()

func (*NodeList) Push

func (n *NodeList) Push(node xml.StartElement)

type TransformFunc

type TransformFunc func(parents *NodeList, in xml.Token) []xml.Token

TransofrmFunc is a function that can transform incoming token into a series of outgoing tokens when traversing XML tree

func Combine

func Combine(funcs ...TransformFunc) TransformFunc

Combine takes a list of TransformFuncs and converts them into a single transform function applying all functions one by one

func InjectNodesIf

func InjectNodesIf(nodes []xml.Token, cond ConditionFunc) TransformFunc

InjectNodes injects nodes at the end of the tag that matches name

func ReplaceAttributeIf

func ReplaceAttributeIf(attrName, attrValue string, cond ConditionFunc) TransformFunc

ReplaceAttribute replaces the attribute of the first node that matches the name

func ReplaceCDATAIf

func ReplaceCDATAIf(val xml.CharData, cond ConditionFunc) TransformFunc

ReplaceCDATAIf replaces CDATA value of the matched node if the parent node name matches the name

Jump to

Keyboard shortcuts

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