XMLParser

package
v0.0.0-...-546f9d4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package XMLParser provides methods for working with XMLParser object instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsXMLParser() Instance
}

type Instance

type Instance [1]gdclass.XMLParser

Provides a low-level interface for creating parsers for [url=https://en.wikipedia.org/wiki/XML]XML[/url] files. This class can serve as base to make custom XML parsers. To parse XML, you must open a file with the [method open] method or a buffer with the [method open_buffer] method. Then, the [method read] method must be called to parse the next nodes. Most of the methods take into consideration the currently parsed node. Here is an example of using [XMLParser] to parse an SVG file (which is based on XML), printing each element and its attributes as a dictionary: [codeblocks] [gdscript] var parser = XMLParser.new() parser.open("path/to/file.svg") while parser.read() != ERR_FILE_EOF:

if parser.get_node_type() == XMLParser.NODE_ELEMENT:
    var node_name = parser.get_node_name()
    var attributes_dict = {}
    for idx in range(parser.get_attribute_count()):
        attributes_dict[parser.get_attribute_name(idx)] = parser.get_attribute_value(idx)
    print("The ", node_name, " element has the following attributes: ", attributes_dict)

[/gdscript] [csharp] var parser = new XmlParser(); parser.Open("path/to/file.svg"); while (parser.Read() != Error.FileEof)

{
    if (parser.GetNodeType() == XmlParser.NodeType.Element)
    {
        var nodeName = parser.GetNodeName();
        var attributesDict = new Godot.Collections.Dictionary();
        for (int idx = 0; idx < parser.GetAttributeCount(); idx++)
        {
            attributesDict[parser.GetAttributeName(idx)] = parser.GetAttributeValue(idx);
        }
        GD.Print($"The {nodeName} element has the following attributes: {attributesDict}");
    }
}

[/csharp] [/codeblocks]

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsXMLParser

func (self Instance) AsXMLParser() Instance

func (Instance) GetAttributeCount

func (self Instance) GetAttributeCount() int

Returns the number of attributes in the currently parsed element. [b]Note:[/b] If this method is used while the currently parsed node is not [constant NODE_ELEMENT] or [constant NODE_ELEMENT_END], this count will not be updated and will still reflect the last element.

func (Instance) GetAttributeName

func (self Instance) GetAttributeName(idx int) string

Returns the name of an attribute of the currently parsed element, specified by the [param idx] index.

func (Instance) GetAttributeValue

func (self Instance) GetAttributeValue(idx int) string

Returns the value of an attribute of the currently parsed element, specified by the [param idx] index.

func (Instance) GetCurrentLine

func (self Instance) GetCurrentLine() int

Returns the current line in the parsed file, counting from 0.

func (Instance) GetNamedAttributeValue

func (self Instance) GetNamedAttributeValue(name string) string

Returns the value of an attribute of the currently parsed element, specified by its [param name]. This method will raise an error if the element has no such attribute.

func (Instance) GetNamedAttributeValueSafe

func (self Instance) GetNamedAttributeValueSafe(name string) string

Returns the value of an attribute of the currently parsed element, specified by its [param name]. This method will return an empty string if the element has no such attribute.

func (Instance) GetNodeData

func (self Instance) GetNodeData() string

Returns the contents of a text node. This method will raise an error if the current parsed node is of any other type.

func (Instance) GetNodeName

func (self Instance) GetNodeName() string

Returns the name of a node. This method will raise an error if the currently parsed node is a text node. [b]Note:[/b] The content of a [constant NODE_CDATA] node and the comment string of a [constant NODE_COMMENT] node are also considered names.

func (Instance) GetNodeOffset

func (self Instance) GetNodeOffset() int

Returns the byte offset of the currently parsed node since the beginning of the file or buffer. This is usually equivalent to the number of characters before the read position.

func (Instance) GetNodeType

func (self Instance) GetNodeType() gdclass.XMLParserNodeType

Returns the type of the current node. Compare with [enum NodeType] constants.

func (Instance) HasAttribute

func (self Instance) HasAttribute(name string) bool

Returns [code]true[/code] if the currently parsed element has an attribute with the [param name].

func (Instance) IsEmpty

func (self Instance) IsEmpty() bool

Returns [code]true[/code] if the currently parsed element is empty, e.g. [code]<element />[/code].

func (Instance) Open

func (self Instance) Open(file string) error

Opens an XML [param file] for parsing. This method returns an error code.

func (Instance) OpenBuffer

func (self Instance) OpenBuffer(buffer []byte) error

Opens an XML raw [param buffer] for parsing. This method returns an error code.

func (Instance) Read

func (self Instance) Read() error

Parses the next node in the file. This method returns an error code.

func (Instance) SeekTo

func (self Instance) SeekTo(position int) error

Moves the buffer cursor to a certain offset (since the beginning) and reads the next node there. This method returns an error code.

func (Instance) SkipSection

func (self Instance) SkipSection()

Skips the current section. If the currently parsed node contains more inner nodes, they will be ignored and the cursor will go to the closing of the current element.

func (*Instance) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type NodeType

type NodeType = gdclass.XMLParserNodeType //gd:XMLParser.NodeType
const (
	/*There's no node (no file or buffer opened).*/
	NodeNone NodeType = 0
	/*An element node type, also known as a tag, e.g. [code]<title>[/code].*/
	NodeElement NodeType = 1
	/*An end of element node type, e.g. [code]</title>[/code].*/
	NodeElementEnd NodeType = 2
	/*A text node type, i.e. text that is not inside an element. This includes whitespace.*/
	NodeText NodeType = 3
	/*A comment node type, e.g. [code]<!--A comment-->[/code].*/
	NodeComment NodeType = 4
	/*A node type for CDATA (Character Data) sections, e.g. [code]<![CDATA[CDATA section]]>[/code].*/
	NodeCdata NodeType = 5
	/*An unknown node type.*/
	NodeUnknown NodeType = 6
)

Jump to

Keyboard shortcuts

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