dom4g

package module
v0.0.0-...-cbd3d37 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: BSD-3-Clause Imports: 7 Imported by: 4

README

golang 的xml处理库

dom4g提供xml简便的操作方法,如节点 增加,删除,查询,属性增加,修改,删除,查询等功能

方法简单介绍:

导入xml文档:返回Element指针
  1. LoadByStream
  2. LoadByXml 参数为字符串

创建节点

  1. LoadByStream
  2. LoadByXml
  3. NewElement 返回指定名字与值的Element指针

转字符串输出

  1. ToString 当前节点xml字符串
  2. ToXml 整个文档xml字符串
  3. SyncToXml 输出整个文档xml字符串,为同步方法,加锁对所有节点都会起作用
  4. DocLength 整个文档的节点数

获取节点名字,值,属性

  1. 获取Element的Name(),Value,Attrs(属性集合)

属性操作

  1. AttrValue 返回指定名字的属性的值
  2. AddAttr 给当前节点增加一个指定名字与值的属性
  3. RemoveAttr 删除指定名字的属性

子节点操作

  1. Node 返回指定名字的Element子节点
  2. Nodes 返回指定名字的Element 集合
  3. NodesLength 返回子节点个数
  4. AllNodes 返回所有子节点集合
  5. RemoveNode 删除指定名字的子节点(可能有多个相同名字的节点,将都被删除)
  6. AddNode 增加一个子节点
  7. AddNodeByString 增加一个子节点,参数为字符串如:b 结构需为xml结构

获取父节点

  1. Parent 返回父节点Element指针,若当前节点为根节点,则返回nil

具体操作可以见测试文件dom_test.go

Documentation

Overview

*

*donnie4w@gmail.com

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attr

type Attr struct {
	Value string
	// contains filtered or unexported fields
}

func (*Attr) Name

func (a *Attr) Name() string

type E

type E interface {
	ToString() string
}

type Element

type Element struct {
	Value string
	Attrs []*Attr
	// contains filtered or unexported fields
}

func LoadByStream

func LoadByStream(r io.Reader) (current *Element, err error)

func LoadByXml

func LoadByXml(xmlstr string) (current *Element, err error)

func NewElement

func NewElement(elementName, elementValue string) (el *Element)

func (*Element) AddAttr

func (t *Element) AddAttr(name, value string)

func (*Element) AddNode

func (t *Element) AddNode(el *Element) error

func (*Element) AddNodeByString

func (t *Element) AddNodeByString(xmlstr string) error

add an element used string for current element

func (*Element) AllNodes

func (t *Element) AllNodes() []*Element

return all the child elements

func (*Element) AttrValue

func (t *Element) AttrValue(name string) (string, bool)

func (*Element) DocLength

func (t *Element) DocLength() int64

whole xml length

func (*Element) GetNodeByPath

func (t *Element) GetNodeByPath(path string) *Element

func (*Element) GetNodesByPath

func (t *Element) GetNodesByPath(path string) []*Element

func (*Element) Head

func (t *Element) Head() string

func (*Element) Name

func (t *Element) Name() string

func (*Element) Node

func (t *Element) Node(name string) *Element

return child element "name"

func (*Element) Nodes

func (t *Element) Nodes(name string) []*Element

return all the child element "name"

func (*Element) NodesLength

func (t *Element) NodesLength() int64

return child element length

func (*Element) Parent

func (t *Element) Parent() *Element

current element's parent

func (*Element) RemoveAttr

func (t *Element) RemoveAttr(name string) bool

remove the attribute "name" for current element

func (*Element) RemoveNode

func (t *Element) RemoveNode(name string) bool

remove the child element "name" for current element

func (*Element) Root

func (t *Element) Root() *Element

return the root element

func (*Element) SyncToXml

func (t *Element) SyncToXml() string

func (*Element) ToString

func (t *Element) ToString() string

func (*Element) ToXML

func (t *Element) ToXML() string

whole xml

Jump to

Keyboard shortcuts

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