Skip to content

Functional, Stream-Based XML Data Extractor #111

@bennobuilder

Description

@bennobuilder

Build a small, composable, functional wrapper around xml-tokenizer to extract structured data from XML streams.

Why

  • Improve DX over XPath/XQuery
  • Avoid full-document parsing (streaming FTW)
  • Encourage functional, testable, and extensible extractors

Example

const Book = extractObject({
  category: attrAt(['book'], 'category'),
  title: textAt(['book', 'title']),
  lang: attrAt(['book', 'title'], 'lang'),
  author: textAt(['book', 'author']),
  year: textAt(['book', 'year']),
  price: pipe(textAt(['book', 'price']), map(Number))
});

runExtractor(xml, pipe(
  matchPath(['bookstore', 'book']),
  matchAttrs({ category: 'COOKING' }),
  collect(Book),
  forEach(console.log)
));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions