This is a k6 extension using the xk6 system.
To build a k6
binary with this plugin, first ensure you have the prerequisites:
- Go toolchain
- Git
Then:
- Install
xk6
:
go install go.k6.io/xk6/cmd/xk6@latest
- Build the binary:
xk6 build --with github.com/rammstein4o/xk6-xml
// 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"]);
});
}