xmlsource

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MaxXMLRows = 100000

MaxXMLRows limits the number of data rows (child elements) that can be loaded from a single XML file to prevent unbounded memory/CPU consumption.

Variables

This section is empty.

Functions

func InferAndConvert added in v0.37.0

func InferAndConvert(val string) any

InferAndConvert tries to convert a string value to its native Go type (int64, float64, bool, time.Time), falling back to string. This mirrors the CSV source's type inference logic.

func NewXmlFSSource added in v0.40.0

func NewXmlFSSource(sys fs.FS, filePath string) *arraysource.Model

NewXmlFSSource reads an XML file from an embedded filesystem (embed.FS / fs.FS) and returns an array-backed data source ready for querying.

func NewXmlFileSource

func NewXmlFileSource(filePath string) *arraysource.Model

NewXmlFileSource reads an XML file and returns an array-backed data source ready for querying with the array driver.

The XML must have a root element containing repeated child elements. Each child element becomes a row. See NewXmlSource for details on column extraction and type inference.

The table name is derived from the filename (without the extension). For example, "data/users.xml" → table name "users".

database.Query().
    Model(neat.NewXmlFileSource("data/users.xml")).
    Where("active = ?", true).
    Get(&users)

Panics if the file cannot be opened, parsed, or has no child elements.

func NewXmlSource

func NewXmlSource(xmlString string, tableName string) *arraysource.Model

NewXmlSource parses an XML string and returns an array-backed data source ready for querying with the array driver.

The XML must have a root element containing repeated child elements. Each child element becomes a row. Column values come from:

  • Attributes on the child element: <user id="1"> → column "id"
  • Leaf sub-elements (text-only): <name>Alice</name> → column "name"
  • Nested sub-elements: stored as JSON strings (queryable via SQLite JSON)

For example:

<users>
  <user id="1">
    <name>Alice</name>
    <active>true</active>
  </user>
  <user id="2">
    <name>Bob</name>
    <active>false</active>
  </user>
</users>

Column types are inferred from string values (int, float, bool, time, string), same as the CSV source.

The table name must be provided explicitly since there is no filename to derive it from. Override with the .Table() method if needed.

database.Query().
    Model(neat.NewXmlSource(xmlString, "users")).
    Where("active = ?", true).
    Get(&users)

Panics if the XML cannot be parsed or has no child elements.

func ParseXMLFSFile added in v0.40.0

func ParseXMLFSFile(sys fs.FS, filePath string) ([]map[string]any, error)

ParseXMLFSFile reads an XML file from an fs.FS (or os.Open if sys is nil) and returns rows.

func ParseXMLFile added in v0.37.0

func ParseXMLFile(filePath string) ([]map[string]any, error)

ParseXMLFile reads an XML file and returns rows.

func ParseXMLReader added in v0.37.0

func ParseXMLReader(r io.Reader) ([]map[string]any, error)

ParseXMLReader parses XML from any io.Reader. It finds the root element, then treats each direct child element as a row. Attributes and leaf sub-elements become columns.

func ParseXMLString added in v0.37.0

func ParseXMLString(content string) ([]map[string]any, error)

ParseXMLString parses an XML string and returns rows.

Types

This section is empty.

Jump to

Keyboard shortcuts

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