xml

package module
v0.0.0-...-165e118 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 6 Imported by: 0

README

xk6-xml

This is a k6 extension using the xk6 system.

Build

To build a k6 binary with this plugin, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
xk6 build --with github.com/koval-jan/xk6-xml

Example

// script.js
import xml from 'k6/x/xml';

export default function () {
    const body = `
    <?xml version="1.0"?>
    <catalog>
        <book id="bk101">
            <author>Gambardella, Matthew</author>
            <title>XML Developer's Guide</title>
            <genre>Computer</genre>
            <price>44.95</price>
            <publish_date>2000-10-01</publish_date>
            <description>
                <![CDATA[An in-depth look at creating applications with XML.]]>
            </description>
        </book>
        <book id="bk102">
            <author>Ralls, Kim</author>
            <title>Midnight Rain</title>
            <genre>Fantasy</genre>
            <price>5.95</price>
            <publish_date>2000-12-16</publish_date>
            <description>
                <![CDATA[A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.]]>
            </description>
        </book>
    </catalog>
    `

    const result = xml.parse(body);

    result["catalog"]["book"].forEach(book => {
        console.log(book["-id"], book["title"]);
    });
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModuleInstance

type ModuleInstance struct {
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exported types for the JS module.

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create module instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface returning a new instance for each VU.

type XML

type XML struct {
	// contains filtered or unexported fields
}

XML is the k6 xml extension.

func (*XML) DecodeXml

func (*XML) DecodeXml(input string) (string, error)

Decode xml

func (*XML) EncodeXml

func (*XML) EncodeXml(input string) (string, error)

Encode xml

func (*XML) FindAll

func (*XML) FindAll(path string, body string) ([]string, error)

func (*XML) FindAllNS

func (*XML) FindAllNS(ns map[string]string, path string, body string) ([]string, error)

func (*XML) FindOne

func (*XML) FindOne(path string, body string) (string, error)

Query xml with xpath

func (*XML) FindOneNS

func (*XML) FindOneNS(ns map[string]string, path string, body string) (string, error)

func (*XML) Parse

func (*XML) Parse(body string) (map[string]interface{}, error)

Parse parses xml

Jump to

Keyboard shortcuts

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