xml

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package xml provides APOC XML processing functions.

This package implements all apoc.xml.* functions for parsing, manipulating, and generating XML data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(text string) string

Escape escapes special XML characters.

Example:

apoc.xml.escape('<tag>') => '&lt;tag&gt;'

func FromJson

func FromJson(jsonStr string) (string, error)

FromJson converts JSON to XML.

Example:

apoc.xml.fromJson(jsonStr) => XML string

func GetAttribute

func GetAttribute(elem *Element, name string) string

GetAttribute gets attribute value.

Example:

apoc.xml.getAttribute(element, 'id') => 'value'

func GetNamespace

func GetNamespace(elem *Element, prefix string) string

GetNamespace gets namespace URI.

Example:

apoc.xml.getNamespace(element, 'ns') => 'http://example.com'

func GetText

func GetText(elem *Element) string

GetText gets text content.

Example:

apoc.xml.getText(element) => 'text content'

func Minify

func Minify(xmlStr string) string

Minify removes whitespace from XML.

Example:

apoc.xml.minify(xmlStr) => minified XML

func Prettify

func Prettify(xmlStr string) (string, error)

Prettify formats XML with indentation.

Example:

apoc.xml.prettify(xmlStr) => formatted XML

func ToJson

func ToJson(xmlStr string) (string, error)

ToJson converts XML to JSON.

Example:

apoc.xml.toJson(xmlStr) => JSON string

func ToMap

func ToMap(elem *Element) map[string]interface{}

ToMap converts XML to map structure.

Example:

apoc.xml.toMap(element) => {name: 'root', children: [...]}

func ToString

func ToString(elem *Element) string

ToString converts structure to XML string.

Example:

apoc.xml.toString(element) => '<root><item>value</item></root>'

func Transform

func Transform(xmlStr, xsltStr string) (string, error)

Transform transforms XML using XSLT.

Example:

apoc.xml.transform(xmlStr, xsltStr) => transformed XML

func Unescape

func Unescape(text string) string

Unescape unescapes XML entities.

Example:

apoc.xml.unescape('&lt;tag&gt;') => '<tag>'

func Validate

func Validate(xmlStr, schemaStr string) map[string]interface{}

Validate validates XML against schema.

Example:

apoc.xml.validate(xmlStr, schemaStr) => {valid: true, errors: []}

Types

type Element

type Element struct {
	Name       string
	Attributes map[string]string
	Text       string
	Children   []*Element
}

Element represents an XML element.

func AddChild

func AddChild(parent, child *Element) *Element

AddChild adds a child element.

Example:

apoc.xml.addChild(parent, child) => parent

func Clone

func Clone(elem *Element) *Element

Clone clones an element.

Example:

apoc.xml.clone(element) => cloned element

func Create

func Create(name string, attributes map[string]string, text string) *Element

Create creates a new element.

Example:

apoc.xml.create('item', {id: '1'}, 'text') => element

func FromMap

func FromMap(data map[string]interface{}) *Element

FromMap creates XML from map structure.

Example:

apoc.xml.fromMap({name: 'root', text: 'value'}) => element

func Namespace

func Namespace(elem *Element, prefix, uri string) *Element

Namespace handles XML namespaces.

Example:

apoc.xml.namespace(element, 'ns', 'http://example.com') => element

func Parse

func Parse(xmlStr string) (*Element, error)

Parse parses XML string to structure.

Example:

apoc.xml.parse('<root><item>value</item></root>') => parsed structure

func Query

func Query(elem *Element, path string) []*Element

Query queries XML using XPath-like syntax.

Example:

apoc.xml.query(element, '//item[@id="1"]') => matching elements

func RemoveChild

func RemoveChild(parent, child *Element) *Element

RemoveChild removes a child element.

Example:

apoc.xml.removeChild(parent, child) => parent

func SetAttribute

func SetAttribute(elem *Element, name, value string) *Element

SetAttribute sets attribute value.

Example:

apoc.xml.setAttribute(element, 'id', 'value') => element

func SetText

func SetText(elem *Element, text string) *Element

SetText sets text content.

Example:

apoc.xml.setText(element, 'new text') => element

Jump to

Keyboard shortcuts

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