xpathutils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAttrSafe

func AddAttrSafe(node *xmlquery.Node, key, value string) bool

AddAttrSafe adds an attribute to the node only if it does not already exist.

Returns true if the attribute was added, false if it already exists.

func ChildNodes

func ChildNodes(node *xmlquery.Node) ([]*xmlquery.Node, error)

ChildNodes returns a slice of all direct child nodes of the given node, excluding attributes, text, comments, and char data. Returns an error if the node type does not support child nodes.

func Children

func Children(node *xmlquery.Node) []*xmlquery.Node

Children returns a slice of all direct child nodes of the given node. This includes all node types that are children, without filtering.

func GetAttrSafe added in v0.1.0

func GetAttrSafe(node *xmlquery.Node, key string) (string, bool)

func GetAttributeNameFromExpression

func GetAttributeNameFromExpression(expr string) (string, bool)

GetAttributeNameFromExpression extracts the attribute name from the expression.

func HasAttr

func HasAttr(node *xmlquery.Node, key string) bool

HasAttr determines if a node has an attribute with the given key.

func HasAttributes

func HasAttributes(node *xmlquery.Node) bool

HasAttributes checks if the node has any attributes.

func IsAttributeExpression

func IsAttributeExpression(expr string) bool

IsAttributeExpression checks if the expression is targeting an attribute.

func IsElementLike

func IsElementLike(node *xmlquery.Node) bool

IsElementLike returns true if the node type supports child nodes.

func LoadXML

func LoadXML(filename string) (*xmlquery.Node, error)

LoadXML loads an XML file and returns the root node.

func NormalizeXPath

func NormalizeXPath(expr string) string

NormalizeXPath ensures that the XPath expression starts with a double slash.

func ParseXmlStr

func ParseXmlStr(xmlStr string) (*xmlquery.Node, error)

ParseXmlStr parses an XML string.

func RemoveAttrSafe

func RemoveAttrSafe(node *xmlquery.Node, key string) bool

RemoveAttrSafe removes an attribute from a node if it exists.

Returns true if the attribute was removed, false otherwise.

func RemoveAttributeFromXPath

func RemoveAttributeFromXPath(expr string) (string, bool)

RemoveAttributeFromXPath trims the trailing attribute selector from an XPath expression, if present. Example: "/root/item/@id" → "/root/item"

func RemoveFromTreeSafe

func RemoveFromTreeSafe(node *xmlquery.Node) bool

RemoveFromTreeSafe removes a node and its subtree from the document tree it is in. If the node is the root of the tree, then it's a no-op.

Returns true if the node was removed, false if it was not.

func SaveXML

func SaveXML(doc *xmlquery.Node, filename string) error

SaveXML saves the XML document to a file.

func Serialize

func Serialize(doc *xmlquery.Node) (string, error)

Serialize serializes the XML document into a string.

func SetAttrSafe

func SetAttrSafe(node *xmlquery.Node, key, value string) bool

SetAttrSafe updates an existing attribute's value, or returns false if the attribute does not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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