xml

package
v0.0.0-...-173cea9 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2012 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XML_PARSE_RECOVER   = 1 << 0  //relaxed parsing
	XML_PARSE_NOERROR   = 1 << 5  //suppress error reports
	XML_PARSE_NOWARNING = 1 << 6  //suppress warning reports
	XML_PARSE_NONET     = 1 << 11 //forbid network access
)

xml parse option

View Source
const (
	XML_ELEMENT_NODE       = 1
	XML_ATTRIBUTE_NODE     = 2
	XML_TEXT_NODE          = 3
	XML_CDATA_SECTION_NODE = 4
	XML_ENTITY_REF_NODE    = 5
	XML_ENTITY_NODE        = 6
	XML_PI_NODE            = 7
	XML_COMMENT_NODE       = 8
	XML_DOCUMENT_NODE      = 9
	XML_DOCUMENT_TYPE_NODE = 10
	XML_DOCUMENT_FRAG_NODE = 11
	XML_NOTATION_NODE      = 12
	XML_HTML_DOCUMENT_NODE = 13
	XML_DTD_NODE           = 14
	XML_ELEMENT_DECL       = 15
	XML_ATTRIBUTE_DECL     = 16
	XML_ENTITY_DECL        = 17
	XML_NAMESPACE_DECL     = 18
	XML_XINCLUDE_START     = 19
	XML_XINCLUDE_END       = 20
	XML_DOCB_DOCUMENT_NODE = 21
)

xmlNode types

View Source
const (
	XML_SAVE_FORMAT   = 1   // format save output
	XML_SAVE_NO_DECL  = 2   //drop the xml declaration
	XML_SAVE_NO_EMPTY = 4   //no empty tags
	XML_SAVE_NO_XHTML = 8   //disable XHTML1 specific rules
	XML_SAVE_XHTML    = 16  //force XHTML1 specific rules
	XML_SAVE_AS_XML   = 32  //force XML serialization on HTML doc
	XML_SAVE_AS_HTML  = 64  //force HTML serialization on XML doc
	XML_SAVE_WSNONSIG = 128 //format with non-significant whitespace
)
View Source
const DefaultEncoding = "utf-8"

libxml2 use "utf-8" by default, and so do we

Variables

View Source
var (
	ERR_UNDEFINED_COERCE_PARAM               = errors.New("unexpected parameter type in coerce")
	ERR_UNDEFINED_SET_CONTENT_PARAM          = errors.New("unexpected parameter type in SetContent")
	ERR_UNDEFINED_SEARCH_PARAM               = errors.New("unexpected parameter type in Search")
	ERR_CANNOT_MAKE_DUCMENT_AS_CHILD         = errors.New("cannot add a document node as a child")
	ERR_CANNOT_COPY_TEXT_NODE_WHEN_ADD_CHILD = errors.New("cannot copy a text node when adding it")
)
View Source
var DefaultEncodingBytes = []byte(DefaultEncoding)

default encoding in byte slice

default parsing option: relax parsing

View Source
var ERR_FAILED_TO_PARSE_XML = errors.New("failed to parse xml input")
View Source
var ErrEmptyFragment = errors.New("empty xml fragment")
View Source
var ErrFailParseFragment = errors.New("failed to parse xml fragment")
View Source
var ErrTooLarge = errors.New("Output buffer too large")

run out of memory

Functions

This section is empty.

Types

type AttributeNode

type AttributeNode struct {
	*XmlNode
}

func (*AttributeNode) SetValue

func (attrNode *AttributeNode) SetValue(val interface{})

func (*AttributeNode) String

func (attrNode *AttributeNode) String() string

func (*AttributeNode) Value

func (attrNode *AttributeNode) Value() string

type CDataNode

type CDataNode struct {
	*XmlNode
}

type Document

type Document interface {
	/* Nokogiri APIs */
	CreateElementNode(string) *ElementNode
	CreateCDataNode(string) *CDataNode
	CreateTextNode(string) *TextNode
	//CreateCommentNode(string) *CommentNode
	ParseFragment([]byte, []byte, int) (*DocumentFragment, error)

	DocPtr() unsafe.Pointer
	DocType() int
	DocRef() Document
	InputEncoding() []byte
	OutputEncoding() []byte
	DocXPathCtx() *xpath.XPath
	AddUnlinkedNode(unsafe.Pointer)
	RemoveUnlinkedNode(unsafe.Pointer) bool
	Free()
	String() string
	Root() *ElementNode
	BookkeepFragment(*DocumentFragment)
}

type DocumentFragment

type DocumentFragment struct {
	Node
	InEncoding  []byte
	OutEncoding []byte
}

func ParseFragment

func ParseFragment(content, inEncoding, url []byte, options int, outEncoding []byte) (fragment *DocumentFragment, err error)

func (*DocumentFragment) Children

func (fragment *DocumentFragment) Children() []Node

func (*DocumentFragment) Remove

func (fragment *DocumentFragment) Remove()

func (*DocumentFragment) String

func (fragment *DocumentFragment) String() string

func (*DocumentFragment) ToBuffer

func (fragment *DocumentFragment) ToBuffer(outputBuffer []byte) []byte

type ElementNode

type ElementNode struct {
	*XmlNode
}

type Node

type Node interface {
	NodePtr() unsafe.Pointer
	ResetNodePtr()
	MyDocument() Document

	IsValid() bool

	ParseFragment([]byte, []byte, int) (*DocumentFragment, error)

	//
	NodeType() int
	NextSibling() Node
	PreviousSibling() Node

	Parent() Node
	FirstChild() Node
	LastChild() Node
	CountChildren() int
	Attributes() map[string]*AttributeNode

	//
	Coerce(interface{}) ([]Node, error)

	//
	AddChild(interface{}) error
	AddPreviousSibling(interface{}) error
	AddNextSibling(interface{}) error
	InsertBefore(interface{}) error
	InsertAfter(interface{}) error
	InsertBegin(interface{}) error
	InsertEnd(interface{}) error
	SetInnerHtml(interface{}) error
	SetChildren(interface{}) error
	Replace(interface{}) error
	Wrap(string) error
	//Swap(interface{}) os.Error
	//
	////
	SetContent(interface{}) error

	//
	Name() string
	SetName(string)

	//
	Attr(string) string
	SetAttr(string, string) string
	Attribute(string) *AttributeNode

	//
	Path() string

	//
	Duplicate(int) Node

	Search(interface{}) ([]Node, error)
	SearchByDeadline(interface{}, *time.Time) ([]Node, error)

	//
	Unlink()
	Remove()
	ResetChildren()
	//Free()
	////
	ToXml([]byte, []byte) ([]byte, int)
	ToHtml([]byte, []byte) ([]byte, int)
	ToBuffer([]byte) []byte
	String() string
	Content() string
	InnerHtml() string
}

func NewNode

func NewNode(nodePtr unsafe.Pointer, document Document) (node Node)

type NodeSet

type NodeSet struct {
	Document
	Nodes []Node
	// contains filtered or unexported fields
}

func NewNodeSet

func NewNodeSet(document Document, nodes interface{}) (set *NodeSet)

func (*NodeSet) Length

func (set *NodeSet) Length() int

func (*NodeSet) Remove

func (set *NodeSet) Remove()

type TextNode

type TextNode struct {
	*XmlNode
}

type WriteBuffer

type WriteBuffer struct {
	Node   *XmlNode
	Buffer []byte
	Offset int
}

type XmlDocument

type XmlDocument struct {
	Ptr *C.xmlDoc
	Me  Document
	Node
	InEncoding    []byte
	OutEncoding   []byte
	UnlinkedNodes map[*C.xmlNode]bool
	XPathCtx      *xpath.XPath
	Type          int
	InputLen      int
	// contains filtered or unexported fields
}

func CreateEmptyDocument

func CreateEmptyDocument(inEncoding, outEncoding []byte) (doc *XmlDocument)

func NewDocument

func NewDocument(p unsafe.Pointer, contentLen int, inEncoding, outEncoding []byte) (doc *XmlDocument)

create a document

func Parse

func Parse(content, inEncoding, url []byte, options int, outEncoding []byte) (doc *XmlDocument, err error)

func (*XmlDocument) AddUnlinkedNode

func (document *XmlDocument) AddUnlinkedNode(nodePtr unsafe.Pointer)

func (*XmlDocument) BookkeepFragment

func (document *XmlDocument) BookkeepFragment(fragment *DocumentFragment)

func (*XmlDocument) CreateCDataNode

func (document *XmlDocument) CreateCDataNode(data string) (cdata *CDataNode)

func (*XmlDocument) CreateElementNode

func (document *XmlDocument) CreateElementNode(tag string) (element *ElementNode)

func (*XmlDocument) CreateTextNode

func (document *XmlDocument) CreateTextNode(data string) (text *TextNode)

func (*XmlDocument) DocPtr

func (document *XmlDocument) DocPtr() (ptr unsafe.Pointer)

func (*XmlDocument) DocRef

func (document *XmlDocument) DocRef() (d Document)

func (*XmlDocument) DocType

func (document *XmlDocument) DocType() (t int)

func (*XmlDocument) DocXPathCtx

func (document *XmlDocument) DocXPathCtx() (ctx *xpath.XPath)

func (*XmlDocument) Free

func (document *XmlDocument) Free()

func (*XmlDocument) InputEncoding

func (document *XmlDocument) InputEncoding() (encoding []byte)

func (*XmlDocument) OutputEncoding

func (document *XmlDocument) OutputEncoding() (encoding []byte)

func (*XmlDocument) ParseFragment

func (document *XmlDocument) ParseFragment(input, url []byte, options int) (fragment *DocumentFragment, err error)

func (*XmlDocument) RemoveUnlinkedNode

func (document *XmlDocument) RemoveUnlinkedNode(nodePtr unsafe.Pointer) bool

func (*XmlDocument) Root

func (document *XmlDocument) Root() (element *ElementNode)

type XmlNode

type XmlNode struct {
	Ptr *C.xmlNode
	Document
	// contains filtered or unexported fields
}

func (*XmlNode) AddChild

func (xmlNode *XmlNode) AddChild(data interface{}) (err error)

func (*XmlNode) AddNextSibling

func (xmlNode *XmlNode) AddNextSibling(data interface{}) (err error)

func (*XmlNode) AddPreviousSibling

func (xmlNode *XmlNode) AddPreviousSibling(data interface{}) (err error)

func (*XmlNode) Attr

func (xmlNode *XmlNode) Attr(name string) (val string)

func (*XmlNode) Attribute

func (xmlNode *XmlNode) Attribute(name string) (attribute *AttributeNode)

func (*XmlNode) Attributes

func (xmlNode *XmlNode) Attributes() (attributes map[string]*AttributeNode)

func (*XmlNode) Coerce

func (xmlNode *XmlNode) Coerce(data interface{}) (nodes []Node, err error)

func (*XmlNode) Content

func (xmlNode *XmlNode) Content() string

func (*XmlNode) CountChildren

func (xmlNode *XmlNode) CountChildren() int

func (*XmlNode) Duplicate

func (xmlNode *XmlNode) Duplicate(level int) (dup Node)

func (*XmlNode) FirstChild

func (xmlNode *XmlNode) FirstChild() Node

func (*XmlNode) InnerHtml

func (xmlNode *XmlNode) InnerHtml() string

func (*XmlNode) InsertAfter

func (xmlNode *XmlNode) InsertAfter(data interface{}) (err error)

func (*XmlNode) InsertBefore

func (xmlNode *XmlNode) InsertBefore(data interface{}) (err error)

func (*XmlNode) InsertBegin

func (xmlNode *XmlNode) InsertBegin(data interface{}) (err error)

func (*XmlNode) InsertEnd

func (xmlNode *XmlNode) InsertEnd(data interface{}) (err error)

func (*XmlNode) IsValid

func (xmlNode *XmlNode) IsValid() bool

func (*XmlNode) LastChild

func (xmlNode *XmlNode) LastChild() Node

func (*XmlNode) MyDocument

func (xmlNode *XmlNode) MyDocument() (document Document)

func (*XmlNode) Name

func (xmlNode *XmlNode) Name() (name string)

func (*XmlNode) NextSibling

func (xmlNode *XmlNode) NextSibling() Node

func (*XmlNode) NodePtr

func (xmlNode *XmlNode) NodePtr() (p unsafe.Pointer)

func (*XmlNode) NodeType

func (xmlNode *XmlNode) NodeType() (nodeType int)

func (*XmlNode) Parent

func (xmlNode *XmlNode) Parent() Node

func (*XmlNode) ParseFragment

func (xmlNode *XmlNode) ParseFragment(input, url []byte, options int) (fragment *DocumentFragment, err error)

func (*XmlNode) Path

func (xmlNode *XmlNode) Path() (path string)

func (*XmlNode) PreviousSibling

func (xmlNode *XmlNode) PreviousSibling() Node

func (*XmlNode) Remove

func (xmlNode *XmlNode) Remove()

func (*XmlNode) Replace

func (xmlNode *XmlNode) Replace(data interface{}) (err error)

func (*XmlNode) ResetChildren

func (xmlNode *XmlNode) ResetChildren()

func (*XmlNode) ResetNodePtr

func (xmlNode *XmlNode) ResetNodePtr()

func (*XmlNode) Search

func (xmlNode *XmlNode) Search(data interface{}) (result []Node, err error)

func (*XmlNode) SearchByDeadline

func (xmlNode *XmlNode) SearchByDeadline(data interface{}, deadline *time.Time) (result []Node, err error)

func (*XmlNode) SetAttr

func (xmlNode *XmlNode) SetAttr(name, value string) (val string)

func (*XmlNode) SetChildren

func (xmlNode *XmlNode) SetChildren(data interface{}) (err error)

func (*XmlNode) SetContent

func (xmlNode *XmlNode) SetContent(content interface{}) (err error)

func (*XmlNode) SetInnerHtml

func (xmlNode *XmlNode) SetInnerHtml(data interface{}) (err error)

func (*XmlNode) SetName

func (xmlNode *XmlNode) SetName(name string)

func (*XmlNode) String

func (xmlNode *XmlNode) String() string

func (*XmlNode) ToBuffer

func (xmlNode *XmlNode) ToBuffer(outputBuffer []byte) []byte

func (*XmlNode) ToHtml

func (xmlNode *XmlNode) ToHtml(encoding, outputBuffer []byte) ([]byte, int)

func (*XmlNode) ToXml

func (xmlNode *XmlNode) ToXml(encoding, outputBuffer []byte) ([]byte, int)
func (xmlNode *XmlNode) Unlink()

func (*XmlNode) Wrap

func (xmlNode *XmlNode) Wrap(data string) (err error)

Jump to

Keyboard shortcuts

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