XMLParser
Provides a low-level interface for creating parsers for XML files.
XMLParser.swift:16class XMLParser
Provides a low-level interface for creating parsers for XML files. This class can serve as base to make custom XML parsers.
To parse XML, you must open a file with the open(file:)
method or a buffer with the openBuffer(_:)
method. Then, the 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 a SVG file (which is based on XML), printing each element and its attributes as a dictionary:
Superclasses
class RefCounted
Base class for reference-counted objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
func getAttributeCount(
) -> Int32 Returns the number of attributes in the currently parsed element.
func getAttributeName(idx: Int32
) -> String Returns the name of an attribute of the currently parsed element, specified by the
idx
index.func getAttributeValue(idx: Int32
) -> String Returns the value of an attribute of the currently parsed element, specified by the
idx
index.func getCurrentLine(
) -> Int32 Returns the current line in the parsed file, counting from 0.
func getNamedAttributeValue(name: String
) -> String Returns the value of an attribute of the currently parsed element, specified by its
name
. This method will raise an error if the element has no such attribute.func getNamedAttributeValueSafe(name: String
) -> String Returns the value of an attribute of the currently parsed element, specified by its
name
. This method will return an empty string if the element has no such attribute.func 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 getNodeName(
) -> String Returns the name of an element node. This method will raise an error if the currently parsed node is not of .nodeElement or .nodeElementEnd type.
func getNodeOffset(
) -> UInt 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 getNodeType(
) -> XMLParser.NodeType Returns the type of the current node. Compare with
NodeType
constants.func hasAttribute(name: String
) -> Bool Returns
true
if the currently parsed element has an attribute with thename
.func isEmpty(
) -> Bool Returns
true
if the currently parsed element is empty, e.g.<element />
.func open(file: String
) -> GodotError Opens an XML
file
for parsing. This method returns an error code.func openBuffer(PackedByteArray
) -> GodotError Opens an XML raw
buffer
for parsing. This method returns an error code.func read(
) -> GodotError Parses the next node in the file. This method returns an error code.
func seek(position: UInt
) -> GodotError Moves the buffer cursor to a certain offset (since the beginning) and reads the next node there. This method returns an error code.
func 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.